On an Apple Keyboard under Linux, how do I make the Function keys work without the fn modifier key?

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


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

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 | 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.

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.