13

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?

18

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.

3

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.

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?

  • 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 3 '14 at 16:10
1

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.

0

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 which of these commands (using the terminal) returns something. Whichever does will tell you which driver you are currently using:

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

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

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

echo 2 > /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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.