Tested on Ubuntu 20.04 running (quite well, actuallyNote 1) on a 2008 MacBook White, but should work on any version of Ubuntu:
First, try this command from this answer:
sudo su -c "echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode"
If it works, great! The problem is you'll have to manually run it every time you reboot your computer.
So, let's make it persistent by adding it to our /etc/rc.local
file, which gets run as root during every boot:
Edit (or create and edit, if running Ubuntu 18.04 or later) the /etc/rc.local
user startup file:
sudo gedit /etc/rc.local
Copy and paste the following line into the file just before the exit 0
line at the end:
echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode
If your /etc/rc.local
file is empty (as it would be on Ubuntu 18.04 and Ubuntu 20.04, for instance, since they don't come with this file installed), copy and paste these entire contents into the file, as this is what it should look like when you're done:
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode
exit 0
Ensure the file is executable:
sudo chmod +x /etc/rc.local
Now reboot your PC.
Done! Every time you reboot your PC, the /etc/rc.local
file automatically gets run as root, calling the echo -n 0x02 > /sys/module/hid_apple/parameters/fnmode
command as root, thereby fixing the fn Function key problem! Now, your F1, F2, F3 etc. keys work as function keys by default, and you must use the fn key with them to call their special functions, rather than the other way around.
References:
- How do I activate Function Keys without pressing the fn button in the mac keyboard?
- https://vpsfix.com/community/server-administration/no-etc-rc-local-file-on-ubuntu-18-04-heres-what-to-do/
Note 1: Be sure to disable animations in Ubuntu 20.04 if running it on a slow or old computer such as a 2008 MacBook, as I am doing, or else it doesn't run nearly as well. Disable them like this:
gsettings set org.gnome.desktop.interface enable-animations false
Sources:
- How to disable animations to speed up screen updating in Virtual environment
- Reduce interface effects to improve performance on 18.04