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?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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:
- 0 = disabled : Disable the ‘fn’ key. Pressing ‘fn’+’F8’ will behave
like you only press ‘F8’- 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.- 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
Method 2
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.
Method 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.
Method 4
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.
Method 5
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?
Method 6
In addition, I suggest update the Kernel configurations with the following command:
sudo update-initramfs -u
Method 7
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
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0