57

I have an apple slim keyboard (USB) and if I want to use one of the Function Key as-is, I also have to press "fn " key first. Otherwise, it will try to perform the other function of the key, such as increasing or decreasing the display intensity, change the volume/mute, etc....

As well, the fn key is actually in the position of the "insert" key for regular keyboards. How can I fix all of that ?

I really like this keyboard, as it make my typing much easier, and much more silent too. But some of those mappings that are different sometime bug me.

Thanks :-)

ButterDog
  • 103
  • 4
jfmessier
  • 2,770
  • 5
  • 26
  • 31

5 Answers5

80
echo 0 > /sys/module/hid_apple/parameters/fnmode

Or, in case of permission issue:

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

This will prevent you from having to reboot. Adding the option is a good idea, so the change persists through reboots.

  • 0 = Fn key disabled
  • 1 = Fn key pressed by default
  • 2 = Fn key released by default

From /drivers/hid/hid-apple.c line 42:

Mode of fn key on Apple keyboards (0 = disabled, [1] = fkeyslast, 2 = fkeysfirst)

Kohistan
  • 133
  • 5
Cynyr
  • 816
  • 7
  • 3
  • 1
    It seems I'm not using an apple driver, so this isn't working for me. I have an off-brand apple keyboard (Razor Black Widow). – Kieveli May 08 '13 at 14:26
  • 1
    @Kieveli when people say apple keyboard they don't mean it generically, they mean as in apple hardware. if the hardware is not apple then you won't be using apple's driver. you gotta find out which driver you're first – DallaRosa Oct 05 '14 at 03:47
  • 5
    For Ubuntu 14.04.3, answer by @cynyr does not works. You get "permission denied". Working one is here: echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode – akikara Aug 20 '15 at 12:27
  • for issues with permission, see [http://askubuntu.com/questions/103643/cannot-echo-hello-x-txt-even-with-sudo](here) – Diogo Mar 23 '17 at 23:17
  • I'm using a KUL ES-87 keyboard which has a hardware OS X Mode switch and this answer works for me. – Michael Fulton Oct 05 '21 at 14:36
  • After an update in `Ubuntu 20`, my dir `/sys/module/hid_apple` was deleted, how can I restore it? – Rodrigo Araujo Aug 24 '22 at 15:22
  • This works for me but the preference does not survive reboot (as expected – [`/sys` is a virtual, RAM-based filesystem](https://www.kernel.org/doc/Documentation/filesystems/sysfs.txt)). To set the preference permanently, follow [wuputah’s answer](https://superuser.com/a/259340/84807). – Melebius Feb 14 '23 at 06:36
42

The answer above about what option to set in /etc/modprobe.d is a bit out of date. Fortunately there is detailed documentation on the Apple Keyboard support:

  1. Edit or create the file /etc/modprobe.d/hid_apple.conf, e.g.:

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

  2. Add this line to the previously open file.

    options hid_apple fnmode=2

  3. Save the file and execute the following command to notify hid_apple module to reload it's configuration.

    sudo update-initramfs -u

  4. Reboot

I'd personally recommend sudo update-initramfs -u -k all to update it for all your kernels (once you are confident the setting works as expected).

Setting the fnmode under /sys still works the same way:

sudo -s 'echo 2 > /sys/module/hid_apple/parameters/fnmode'

The values in both methods are as follows:

  • 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)
wuputah
  • 531
  • 5
  • 8
6

From Here

how do we swap the function of the Fn key?

First edit /etc/modprobe.d/options

sudo nano /etc/modprobe.d/options

and make sure it has the line

options hid pb_fnmode=2

Then save and exit. Lastly, we need to update ramfs:

sudo update-initramfs -u -v -k uname -r

Then just reboot!

joe
  • 12,279
  • 12
  • 67
  • 104
4

This worked for me on Fedora 24

  1. Create a new file for SystemD to start.

    gedit /usr/lib/systemd/system/mac-keyboard.service

    Ensure the file contains the following

    [Unit]
     Description=mac-keyboard
    [Service]
     Type=oneshot
     ExecStart=/bin/sh -c "echo 2 > /sys/module/hid_apple/parameters/fnmode"
     ExecStop=/bin/sh -c "echo 1 > /sys/module/hid_apple/parameters/fnmode"
     RemainAfterExit=yes
    [Install]
     WantedBy=multi-user.target
    
  2. Reload SystemD to read your new file

    systemctl --system daemon-reload

  3. Start the SystemD service.

    systemctl start mac-keyboard.service

  4. Enable service to start on boot.

    systemctl enable mac-keyboard.service

Reference: https://www.dalemacartney.com/2013/06/14/changing-the-default-function-key-behaviour-in-fedora/

FDisk
  • 161
  • 2
1

On Ubuntu 22.04:

echo 1 > /sys/module/hid_apple/parameters/swap_fn_leftctrl

Or add this line into /etc/modprobe.d/hid_apple.conf:

options hid_apple swap_fn_leftctrl=1
Son T
  • 11
  • 1