Turning On Or Off Fn Mode In Ubuntu Linux

I was typing on my Keychron K2 keyboard today and realised that I hadn't used the function keys at all. Not that I hadn't tried a few times, it's just that the function keys were linked to the media keys for the laptop I was using. When I pressed the F2 key it would increase the screen brightness, which was fine, but I realised that I had missed using the function keys for a while.

I was using Ubuntu 20.04 and there appeared to be no option to turn this off in the settings. After a little research I found a solution to the problem.

As it happens, Ubuntu has a setting that allows the function keys to be swapped with the multimedia keys, but this isn't exposed to users via the settings menus. This setting needs to be set manually by the user. As it happens, there are a couple of ways to do this, but they all accept one of three values. These are as follows.

0disabledDisables the 'fn' key. This means that pressing F2 will trigger F2 to be pressed and not the special action key. Pressing 'fn' + F2 will just press the F2 key as normal.
1fkeyslastFunction keys are used as the last key. Pressing F2 will act as the special key. Pressing 'fn' + F2 will trigger F2.
2fkeysfirstFunction keys are used as the first key. Pressing F2 will act as triggering F2. Pressing 'fn' + F2 will act as the special key.

With that list in mind, let's look at the ways to change this setting.


The first way is to temporarily set this value. This means that when you next reboot your machine the value will be put back to the default (which is 1). To do this you just need to echo the value you want into the file at /sys/module/hid_apple/parameters/fnmode.

echo 0 | sudo tee /sys/module/hid_apple/parameters/fnmode

To double check that the value has taken just use cat to print out the contents of the file. It should only contain a single character so the output will be very short.

$ cat /sys/module/hid_apple/parameters/fnmode

To set the value back to 1 use the following.

echo 1 | sudo tee /sys/module/hid_apple/parameters/fnmode

Remember that when you reboot your machine the value will be back to 1.


The second way to do this is to write this value into your system permanently. This involves setting the value of the fnmode to be the value you need, which will then be copied into the fnmode file mentioned above.

echo options hid_apple fnmode=0 | sudo tee -a /etc/modprobe.d/hid_apple.conf

This will do nothing until you trigger copying the configuration into the initramfs boot file. This can be done by killing the update-initramfs service.

sudo update-initramfs -u -k all

You can optionally reboot after this, but the next time you restart your machine the value will be set.

For more information about this (as well as running this on older Ubuntu systems) take a look at the Ubuntu documentation for changing function key behaviour.


Thanks, very helpful!


Great thanks!


Thanks it worked!


Thank you so much! This worked perfectly (also on a Keychron)


Thanks (keychron k1 se)





Philip Norton

Thank you a lot!


Thanks in advance. What if I want to assign a custom shortcut only to the Fn key? Is that possible?


Thanks it worked!


Thanks, it is my issue 


Did not work for me. HP Pavilion laptop (2022) with Lubuntu 22.04


Add new comment

The content of this field is kept private and will not be shown publicly.
2 + 12 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.