Using Apple's Aluminium Keyboard on Linux

~ 26 Sep 2010, 02:39

Here's a mini-HOWTO on the tweaks and hacks to turn the beautiful-but-temperament Apple aluminium keyboard into a PC-compatible one. Having used this gem for about an year now, I can testify: it's, without a doubt, the best keyboard I've ever worked with. It's comfort, quiet, fast, compact, prompts you to keep your fingernails short... you name it :)

The only hitch turns out to be the weird key locations of some symbols, and some Mac-influenced behaviour. You don't have an Insert button, there's a "Fn" button instead (see the picture above); F-keys don't behave as such, but rather do something (e.g., F12 is "volume up"); the numpad keys +, -, *, / are totally different; the key on the left of '1' is strange, it's not a tilde; and, the most painful thing - the Alt and Win keys are swapped (Alt is no more to the left of Space, but one key further left).

Fedora 13 applies the following logic in regard to these PC/Mac mismatches - a key does exactly what is written on it; even if that's different from what all people are used to do. Personally, I find that unacceptable, so here's how I restored a PC-compatible behaviour of the Apple keyboard:

1) Add the following two lines in /etc/rc.local:


echo "2" > /sys/module/hid_apple/parameters/fnmode
echo "0" > /sys/module/hid_apple/parameters/iso_layout


The first line makes the F-keys behave as real F-keys. To access the "action", combine with the "Fn" key. E.g., Fn + F12 turns the volume up.
The second line resolves the tilde issue, among other things.

2) Swapping the Alt and Win keys is best done by modifying the XKB scan-code interpretation file directly:
2.1) In Gnome->Preferences->Keyboard->Layouts, select "Evdev-managed keyboard" as your keyboard device.
2.2) Open /usr/share/X11/xkb/keycodes/evdev in a text editor. Search for any lines of the form "<LALT> = number", "<LWIN> = other number". Now you need to swap the numbers, corresponding to LALT and LWIN, and similarly for RALT and RWIN.
2.3) Restart X.

And that's it! Voilà!



Comments:

#1 by rado, posted on 6 Dec 2010, 13:18


u have to save that evdev file somewhere as a backup, otherwise your changes will disappear on the next fedora X11-related update, which overwrites those files.


#2 by Bauerspule, posted on 10 Jan 2014, 18:29


echo "1" > /sys/module/hid_apple/parameters/swap_opt_cmd on my Linux 3.12. :)

<3


#3 by anrieff, posted on 14 Jan 2014, 13:08


Wow, this makes it much easier. And yet another reason why I love Linux :)


#4 by John, posted on 25 Jan 2014, 02:33


Thank you for this! I was struggling to find the keycodes to the F1 - F12 keys in Fedora 20. Using the fnmode change easily fixed everything in one place.


#5 by Ondo, posted on 31 Jan 2014, 19:39


Is the opposite possible? By this obscure question I mean the following:

I am a Linux Mint user and I want to use the Apple keyboard as it is born. I want the keys to be what is written on them, but the Ubuntu Linux family does what you want: turn it into a PC-keyboard. The Apple key layout is least in my language very superior to the PC-layout - mileage probably varies by language.
So, in brief, can the Fedora solution to native support of the Apple keyboard be transferred to Linux Mint, or other Ubuntu's?
thanks,
Ondo


#6 by anrieff, posted on 1 Feb 2014, 02:18


I guess yes, look for the files in /sys/module/hid_apple/parameters for the FN keys and the likes.
As per the keycode mapping - you can do the same hacks with the evdev file. Let me know if this works for you, as I haven't attempted running the apple keyboard on Ubuntu :)




Nickname:
Contact: (Link to your blog/website/e-mail; not obligatory)
Your comment:

Calculate: fifty-one minus sixty-siх = (type the answer in digits)


<<

Valid XHTML 1.0 Strict