Apple Mac Keyboard on Ubuntu
OSes
The Mac keyboard is still not recognized correctly on Ubuntu 18.04 LTS, and it's been like this for a while. The culprit is the hid_apple kernel module, which doesn't properly detect the keyboard layout. This affects all GNU/Linux distributions, not just Ubuntu.
The result: keys are swapped or don't behave as expected. The instructions in this article apply to Ubuntu and Debian. For other distributions, adapt the input method configuration using the appropriate tool.
Input method
Configure the text input settings, either through the "Text Input" / "Keyboard Layouts" utility or directly in /etc/default/keyboard with the following values:
XKBMODEL="pc105" # Generic 105-key PC (intl.)
XKBLAYOUT="fr" # French
XKBVARIANT="mac" # French (Macintosh)
Then apply the changes:
sudo dpkg-reconfigure -f noninteractive keyboard-configuration
Key layout
In Europe, keyboards typically use the ISO standard. But here, you need to disable it.
echo 0 | sudo tee /sys/module/hid_apple/parameters/iso_layout
Swapping Cmd and Alt keys
echo 1 | sudo tee /sys/module/hid_apple/parameters/swap_opt_cmd
Function key behavior
- 0 - Disables the
fnkey entirely. - 1 - Enabled by default. Pressing
F8triggers the play/pause action.fn + F8triggersF8. - 2 - Disabled by default. Pressing
F8triggersF8.fn + F8triggers the play/pause action.
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode
Persisting the changes
To make these changes survive a reboot, persist them in modprobe and regenerate the initramfs:
echo options hid_apple iso_layout=0 | sudo tee -a /etc/modprobe.d/hid_apple.conf
echo options hid_apple swap_opt_cmd=0 | sudo tee -a /etc/modprobe.d/hid_apple.conf
echo options hid_apple fnmode=2 | sudo tee -a /etc/modprobe.d/hid_apple.conf
sudo update-initramfs -u -k all