76

I use an Apple wired keyboard on Linux. By default the function keys (F1, F2, F3, etc) require the fn key to be pressed for them to work. Without the fn key, these keys control the features like Screen Brightness, Volume, and Music Track Control.

Is there any way to swap these around, so the Function keys do not require the fn modifier, but the other functions (Brightness etc) do?

ryanlerch
  • 925

7 Answers7

106

You need to add 0 or 2 into /sys/module/hid_apple/parameters/fnmode.

i.e.:

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

There seems to be some confusion regarding what the difference between the two values might be. Quoting the Ubuntu documentation:

  1. 0 = disabled : Disable the 'fn' key. Pressing 'fn'+'F8' will behave like you only press 'F8'
  2. 1 = fkeyslast : Function keys are used as last key. Pressing 'F8' key will act as a special key. Pressing 'fn'+'F8' will behave like a F8.
  3. 2 = fkeysfirst : Function keys are used as first key. Pressing 'F8' key will behave like a F8. Pressing 'fn'+'F8' will act as special key (play/pause).

Note that this also works for me on Fedora.


As several people have commented, this change is temporary. You can stick it in your login shell's RC file or into cron so that you don't have to worry about it.

You can also change your driver settings to make this change permanent, like so:

echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf
sudo update-initramfs -u -k all
# reboot when convenient

credits to https://askubuntu.com/a/7553

ffledgling
  • 1,379
  • it's fnmode = no underscore – Yauhen Yakimovich Jan 22 '16 at 15:46
  • 1
    This also works with the M87 keyboard from "velocifire". It is a budget mechanical keyboard but thank you so much for the fix, shows up as an Apple USB device so the apple_hid parameter fix worked for it as well!! So happy can use this kb now. – shaunhusain Jun 05 '20 at 21:25
  • in some systems need 2 in quote: echo "2"> /sys/module/hid_apple/parameters/fnmode and well done. – Ryabinin Sergey Aug 03 '20 at 23:20
  • 3
    To make this change permanent (after reboot, the value was reset automatically for me), see https://askubuntu.com/a/7553/197712 – Bikash Gyawali Sep 28 '20 at 09:40
  • 1
    As @bikashg said, this change is not permanent and making it so should be part of this answer. – Shautieh Jan 27 '21 at 01:15
  • Awesome! Worked perfectly on a 2015 MacBook Air that I just upgraded with a new SSD and onto which I installed dualboot MacOS 12 (installed for free via the Mac "internet boot" option--see my comments at the bottom of my website article here) and Linux Ubuntu 22.04.3! I simply ran sudo gedit /etc/modprobe.d/hid_apple.conf and then added options hid_apple fnmode=2 to the top of that file to get the desired effect. Then, reboot. Works perfectly! Upvoted. – Gabriel Staples Dec 25 '23 at 06:38
13

For anyone stumbling upon this thread using one of the newer MacBook Pros (2016 and later) which need the applespi driver to make the keyboard and touchpad work, here's how to make this work, as I couldn't find any other thread explaining this for newer Macs.

As far as I understand, the driver effectively replaces the role of the hid_apple module, so the files to edit are slightly different.

First, to verify that you are using the applespi driver and not the hid_apple driver, check what this command returns (using the terminal). It will tell you which driver you are currently using:

# If this returns "applespi", you are using applespi
ls /sys/module | grep -e applespi -e hid_apple

To test settings temporarily (settings will be reset after a reboot):

echo 2 | sudo tee -a /sys/module/applespi/parameters/fnmode

To apply the changes permanently (persist with reboots):

# Add the option for the fn key
echo options applespi fnmode=2 | sudo tee -a /etc/modprobe.d/applespi.conf
# Update initramfs bootfile
sudo update-initramfs -u -k all
# Reboot to test (optional)
sudo reboot

For older MacBook Pros using the hid_apple module, use "hid_apple" rather than "applespi" in the commands.

Misha
  • 131
4

I figured out that it is pretty simple to change the behaviour of this modifier, As root change the value in the file /sys/module/hid_apple/parameters/fnmode from 1 to 0. For example:

# echo 0 > /sys/module/hid_apple/parameters/fnmode

Note that in some older versions of linux, this file was located in /sys/module/apple/parameters/fnmode. Also, this change will not persist when you reboot.

ryanlerch
  • 925
2

For those who get access denied and could not simply prefix "sudo" use:

sudo nano /sys/module/hid_apple/parameters/fnmode

Change it to 2 or whatever and then Ctrl+X to save.

Marc
  • 412
  • better way is to echo 2| sudo tee /sys/module/hid_apple/parameters/fnmode, but all these solutions are transient ....

    One way to make persistent (on systemd environments like Fedora for example) : echo "w /sys/module/hid_apple/parameters/fnmode - - - - 2" | sudo tee /etc/tmpfiles.d/rev_fn_key.conf

    – nhed Oct 11 '19 at 20:50
2

In addition, I suggest update the Kernel configurations with the following command:

sudo update-initramfs -u
samueldc
  • 69
  • 5
1

In an older discussion a solution is given with a kernel boot parameter which might be preferable (system-wide application, modification of just a line in /etc/default/grub, etc).

Only according to that solution, fnmode is set to 2 instead of 0. I just tried to set hid_apple/parameters/fnmode to 2, and it has the desired effect too. Maybe the logic is simply `1 → "require Fn to access F1, F2, F3,..." vs. all other values?

drs
  • 5,453
RJVB
  • 254
  • 1
    Hi RJVB, welcome to unix.SE. I've edited your answer to improve the formatting. Take a look at the source to learn some of the tricks. – drs Jun 03 '14 at 16:10
1

In addition to @ffledgling's answer:

I suggest the following in order to make this setting being applied on every reboot (works fine on Ubuntu 18.04, 20.04 and I think other distributions as well):

echo "options hid_apple fnmode=2" | sudo tee /etc/modprobe.d/hid_apple.conf
mistapink
  • 161