Use Function Keys without pressing the fn button in the mac keyboard?

I am using an Apple keyboard. To get the default functionality of the function keys, I need to press fn+Function key.

This is quite annoying since I frequently use the function keys for debugging.

Is there any way I can get the default functionality out of the function keys, i.e., get the effect of pressing the Fn key without having to actually press it?


Solution 1:

The article there should help you.

https://help.ubuntu.com/community/AppleKeyboard

I inserted these two echo lines into /etc/rc.local:

echo 2 > /sys/module/hid_apple/parameters/fnmode
echo 2 > /sys/module/apple/parameters/fnmode

Those are inserted just before the "exit 0" line.

Solution 2:

From the Ubuntu community wiki on Apple Keyboards... Open this file with root permissions in terminal:

gksudo gedit /etc/modprobe.d/hid_apple.conf

Then add to the end of the file:

options hid_apple fnmode=2

And then finally in terminal...

sudo update-initramfs -u

Reboot your computer.

This will change the default keys to being the Function keys, E.g F8 is F8 instead of Play/Pause song. Hope this helps! ^.^

Solution 3:

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:

  1. How do I activate Function Keys without pressing the fn button in the mac keyboard?
  2. 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:

  1. How to disable animations to speed up screen updating in Virtual environment
  2. Reduce interface effects to improve performance on 18.04