I own a cabled, aluminium Apple-Keyboard (which seems to be discontinued). And I like it. It has a good feel to it and I like the distance between the Keys. I know there are very similar Keyboards like the Cherry STRAIT or the matias Mac-Keyboard but, well, it's Linux so it should be possible to map the Keyboary-Scancodes to whichever logical Keys you want, right?
![Wired Apple keyboard] ({static}keyboard.jpg "Wired Apple keyboard, anodized aluminum (2007)") Image CC-BY 2.0 by http://flickr.com/people/rudolf_schuba/
Turns out, it is; but it is far from obvious how it has to be done. So here I write down how I accomplished it, but there are probably even more options including adding your all DKMS Kernel-Patches, like suggested by the Ubuntu-Wiki. I'm writing this for an Ubuntu 18.04, but the Solution might also work on Ubuntu 16.04 or Newer Debians.
Step 1: Keyboard Layout
Probably the most obvious change: Set your Keyboard-Layout to one of the Mac-Variants.
For me the right one is called German - (Macintosh, no dead keys)
or
German - (Macintosh)
– depending on your preferred flavor, both in the
German (Germany)
group. This will map
Alt-N
to~
Alt-E
to€
Alt-L
to@
- …
This does however leave your Function-Keys F1-F12
mapped to their
Multimedia-Functions, Alt/Super
is still swapped and some of the Second-Level
Keys are still wrong, especially
<
>
^
are still wrong.
Step 2: Kernel Module hid-driver
They are fixable by setting a kernel-Option iso_layout
on the
hid_apple
-module to 0
(Default-Value is 1
), so that it actually supports
non-english keyboard layouts:
echo 0 | sudo tee /sys/module/hid_apple/parameters/iso_layout
Next up are the function-keys. Setting the Option fnmode
to 2
gives a
reasonable behaviour. Citing from the Ubuntu-Wiki:
- 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).
echo 2 | sudo tee /sys/module/hid_apple/parameters/fnmode
To persist these options, copy them into a modprobe
-Config and regenerate
initramfs
:
echo 'options hid_apple fnmode=2 iso_layout=0 swap_opt_cmd=0' | sudo tee /etc/modprobe.d/hid_apple.conf
sudo update-initramfs -u -k all
But what's about swap_opt_cmd
, I hear you ask? Unfortunately setting this
Option to 1
will swap Alt
and Super
-Keys, Left and Right – but in Reality
only the Left keys are swapped in Hardware, when compared to a Mac with this
Keyboard connected. Setting this Option would actually remove the Alt-Key from
your right Hand.
So ne need another Option to only swap the left Key:
Step 3: Gnome Tweak Tool
Gnome Tweak-Tool to the rescue:
![Gnome Tweak-Tool showing the Setting "Left Alt is swapped with Left Win" in the "Additional Layout Oprions" under the "Keyboard & Mouse" Tab] ({static}tweak.png "Left Alt is swapped with Left Win")
With the Gnome Tweak-Tool it's possible to only swap the left Keys, which is exactly wht I want.
Step 4: Hotkeys
As a last thing, I added some Hotkeys I'm used to have from my MacBook, for
Example Super-4
for gnome-screenshot --area
.
I also like to setup some Hotkeys for moving Windows around, but they are not Mac-Specific and ask for another Blog-Post.