16

I am using an Apple keyboard. To get the default functionality of the function keys, I need to press fn+Function key.

This is quite annoying since I frequently use the function keys for debugging.

Is there any way I can get the default functionality out of the function keys, i.e., get the effect of pressing the Fn key without having to actually press it?

  • Suggestion: Use the USB cable with wireless. Which model of the Apple Keyboard? I'm using "Magic Keyboard with Numeric Keypad" (Model A1843) with a Lenovo T470s running Ubuntu 18.04 Gnome. When I click the "fn" button it dims my laptop display! So does the F1 button. Gnome says they're both the "Monitor brightness down" button according to the Keyboard Shortcuts setting panel. BUT... When USB is plugged in, the fn key works correctly.... And F1 makes it dim, F2 makes it bright. So the bluetooth causes mappings to become problematic it appears. – iJames May 16 '19 at 19:43

4 Answers4

14

The article there should help you.

https://help.ubuntu.com/community/AppleKeyboard

I inserted these two echo lines into /etc/rc.local:

echo 2 > /sys/module/hid_apple/parameters/fnmode
echo 2 > /sys/module/apple/parameters/fnmode

Those are inserted just before the "exit 0" line.

Tim
  • 32,861
  • 27
  • 118
  • 178
jfmessier
  • 6,126
  • 3
    Found only the first echo 2 > /sys/module/hid_apple/parameters/fnmode was enough for me on ubuntu 12.04 with alum apple wired keybd. – Maks Mar 27 '13 at 23:12
  • You can use echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode so you won't have to drop into root shell to run the command. – Dan Feb 12 '16 at 12:14
  • 1
    I know this is an old thread, but this problem exists in 16.04. This solution was accepted, but the one below seems like "the right way" (tm). Would you agree? – Ivan Perez May 01 '16 at 15:26
  • This is a very good answer compared to the other solutions. 1) It still works in ubuntu 20.04 2) It does not depend on gnome or any specific desktop - it is on a "lower level" and hardware stuff should be handled on a low level, so it works on all the upper levels 3) It uses what is already there and does not need an external application 4) It is simple and easy – mit Apr 23 '20 at 13:11
  • this worked for me 18.04, but only the first step was needed – Derek Eden Apr 26 '20 at 23:45
  • Note: Ubuntu 18.04 and 20.04 don't come with an /etc/rc.local file installed, which is confusing, so here's how to create it and get the proper functionality we want: https://askubuntu.com/a/1265768/327339. I used just the echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode command in the rc.local file too. – Gabriel Staples Aug 09 '20 at 16:53
6

From the Ubuntu community wiki on Apple Keyboards... Open this file with root permissions in terminal:

gksudo gedit /etc/modprobe.d/hid_apple.conf

Then add to the end of the file:

options hid_apple fnmode=2

And then finally in terminal...

sudo update-initramfs -u

Reboot your computer.

This will change the default keys to being the Function keys, E.g F8 is F8 instead of Play/Pause song. Hope this helps! ^.^

Alex Stevens
  • 1,300
  • This worked for 14.04 on MacBook Pro 8,1. Thanks! – mcmlxxxiii May 18 '15 at 08:18
  • Works on 16.04 as well. – Lambart Sep 27 '16 at 04:40
  • I prefer very much the answer from @jfmessler which is currently the accepted answer: https://askubuntu.com/a/33660/1467 Reasons why, see my comment on that answer – mit Apr 23 '20 at 13:12
  • This doesn't seem to apply on MacBook 2008 White running Ubuntu 20.04. File gksudo gedit /etc/modprobe.d/hid_apple.conf doesn't exist. :( – Gabriel Staples Aug 08 '20 at 23:16
  • works on Ubuntu 22.04.

    the hid_apple.conf does not initially exist, but that is ok. This is a single line command:

    sudo bash -c "echo options hid_apple fnmode=2 >> /etc/modprobe.d/hid_apple.conf"

    – Yura Fedoriv Oct 19 '23 at 07:06
2

Tested on Ubuntu 20.04 running (quite well, actuallyNote 1) on a 2008 MacBook White, but should work on any version of Ubuntu:

First, try this command from this answer:

sudo su -c "echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode"

If it works, great! The problem is you'll have to manually run it every time you reboot your computer.

So, let's make it persistent by adding it to our /etc/rc.local file, which gets run as root during every boot:

Edit (or create and edit, if running Ubuntu 18.04 or later) the /etc/rc.local user startup file:

sudo gedit /etc/rc.local

Copy and paste the following line into the file just before the exit 0 line at the end:

echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode

If your /etc/rc.local file is empty (as it would be on Ubuntu 18.04 and Ubuntu 20.04, for instance, since they don't come with this file installed), copy and paste these entire contents into the file, as this is what it should look like when you're done:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode

exit 0

Ensure the file is executable:

sudo chmod +x /etc/rc.local

Now reboot your PC.

Done! Every time you reboot your PC, the /etc/rc.local file automatically gets run as root, calling the echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode command as root, thereby fixing the fn Function key problem! Now, your F1, F2, F3 etc. keys work as function keys by default, and you must use the fn key with them to call their special functions, rather than the other way around.

References:

  1. How do I activate Function Keys without pressing the fn button in the mac keyboard?
  2. https://vpsfix.com/community/server-administration/no-etc-rc-local-file-on-ubuntu-18-04-heres-what-to-do/

Note 1: Be sure to disable animations in Ubuntu 20.04 if running it on a slow or old computer such as a 2008 MacBook, as I am doing, or else it doesn't run nearly as well. Disable them like this:

gsettings set org.gnome.desktop.interface enable-animations false

Sources:

  1. How to disable animations to speed up screen updating in Virtual environment
  2. Reduce interface effects to improve performance on 18.04
0
sudo add-apt-repository ppa:daniel.pavel/solaar
sudo apt-get update
sudo apt-get install solaar
solaar

This installs and starts the solaar application.

With a mac keyboard there will be a radio button to toggle fn in the solaar gui.

enter image description here

mit
  • 2,121