I wouldn’t usually post something of this sort on my usability blog, since it requires a bit of hacking that I would ordinarily say makes for bad usability. However, I really like my Apple keyboard, and although it takes a bit of effort to get it working as well as I would like in Fedora, the end result means I get the same user experience out of my keyboard in Linux as I do on the Mac, so this is a good thing.
Also, I recently re-installed Fedora, and forgot how I’d previously set up my keyboard, so after a few hours research I really want to make a note of how I did it for the next time I have to go through the ordeal
Basic usage
The Apple keyboards are generally pretty well-supported in Fedora and Linux generally. “Out of the box”, the brightness keys, the audio playback keys, the volume keys, the eject key, and the function key all work as expected.
Command key
By default, the Command key on the Apple keyboard is mapped to the Linux Super key. This is the same key that the Windows key is mapped to on Windows keyboards. If you’re used to Mac OSX, you may not have much use for the Super key, and instead you’ll find yourself pressing Command for keyboard shortcuts that use Control in Linux, such as Ctrl+C, Ctrl+V, and Ctrl+Z.
So, I simply mapped the Command key to be the same as the Control key. This way whenever I press Cmd+V, I actually get Ctrl+V. In Gnome, this is fairly easy to re-map. Go to System > Preferences > Keyboard, select the Layouts tab, and click the Options button. Expand the Alt/Win key behavior section, then check the box for Control is mapped to Win keys (and the usual Ctrl keys).
Now you can use the shortcuts you’re familiar with from the Mac OS without reassigning them all. Alternatively, if you still want access to the Super key, you can just remap the left Command key to Control and keep the right Command key mapped to the Super key. This is a bit more complicated, and is covered below.
Option key
In Mac OS, the Option key can be used to type special characters. For example, to type é, you press Opt+e, then e. Since I work with words a lot, I find this very useful.
In Linux, however, special characters are accessed using the Compose key. I actually find the Linux way of getting special characters a lot more intuitive; instead of having to remember the key combination to press as in Mac OS, you instead use the Compose key to combine two characters that look like what you want as the end result. For example, to type é in Linux, you type Compose+’, then e. To type è, you type Compose+`, then e. To type €, you type Compose+=, then e. Though still a little tricky, it is a bit easier to figure out than on the Mac.
However, for all this, you need a Compose key, and neither Apple nor Microsoft keyboards have one. So again, you need to map another key to the Compose key. Option is the obvious choice, but you’ll still need the Option key to use as an Alt key. So the solution I found best was to just map the right Option key, which I otherwise never use, to the Compose key.
This is also quite simple to do. Go to System > Preferences > Keyboard, select the Layouts tab, and click the Options button. Expand the Compose key position section, then check the box for Right Alt.
Special function keys
As I mentioned previously, most of the special function keys work out of the box. However, two of them don’t: the Exposé key and the Dashboard key. What’s more, they don’t have a key symbol assigned to them, so you can’t easily remap them.
You may not have a use for these keys, and if so you needn’t bother assigning them. However, if you use an Exposé-equivalent such as the Compiz Fusion Scale, and a Dashboard-equivalent such as the Compiz Fusion Widgets, you’ll probably find it useful to have these key working as expected.
So here’s where things get a bit tricky and we unfortunately have to turn to hacking. First we need to find the key codes for the two keys, then assign them unique key symbols, then assign those key symbols to the function we want.
To find the key codes, I used a program called Xev. You can run it from the terminal by entering the command xev. You’ll then see a small window open up, and your terminal will report any mouse and keyboard interaction with the window. Press the Exposé key and Dashboard key, and the terminal will report a KeyPress and KeyRelease event. It should tell you the key code, followed by a key symbol of NoSymbol:
keycode 128 (keysym 0x0, NoSymbol)
Make a note of the key codes. For my keyboard, the Exposé key was code 128 and the Dashboard key was code 212. Yours will probably be the same.
Next, we assign the key codes to unique key symbols using the xmodmap program. Create a new text file in your home directory named .apple_keys. Add the following two lines and save the file:
keycode 128 = XF86RotateWindowskeycode 212 = XF86Calculator
If your key codes were different than mine, use those ones instead. I chose the above key symbols because they seemed to be the closest symbols to what the keys do, and they’re not assigned to any other keys on the Apple keyboard.
Once your file is saved, re-source it by entering the following command:
$ xmodmap ~/.apple_keys
You’ll probably want to add this line to your ~/.xprofile file (thanks to Shaun for pointing this out) so that it gets sourced whenever you start your computer.
Now, we’re on the home stretch. Open up the settings for your Exposé and Dashboard equivalents and assign your new special function keys to them. If you’re using Compiz Fusion, run the CompizConfig Settings Manager, select Scale, then assign the new Exposé key to the Initiate Window Picker event. Go back to the main menu, select Widget Layer, then assign the new Dashboard key to the Toggle Widget Display event. You’re done!
Keeping the Super key
As I mentioned above, instead of mapping both your Command keys to be Control keys, you may want to keep the Super key around. You might want to just map the left Command key to a Control key, but keep the right Command key as the Super key. Unfortunately, this variation isn’t one of the options in the Gnome keyboard settings, so we’ll have to do it using xmodmap.
Instead of following the above instructions for the Command key, add the following line to the .apple_keys file:
keycode 133 = Control_L
Again, your key code may be different, so just check it using xev as described above.
Re-source the file, and the re-mapping should be complete.
References
My main reason for writing this as because it took me a while to figure out, and when I had to do it a second time I’d forgotten how to do it all. I pieced together the above information using the following separate sources, none of which by themselves told me all the information I needed. That’s life with Linux, though!
http://linuxtidbits.wordpress.com/2008/04/19/apple-keyboards-in-linux/ http://wiki.archlinux.org/index.php/Extra_Keyboard_Keys_in_Xorg https://help.ubuntu.com/community/AppleKeyboard http://keytouch.sourceforge.net/howto_keyboard.php

Hi,
You can make your changes permanent by putting:
xmodmap ~/.apple_keysinto ~/.xprofile.
Cheers
Shaun
Thanks! My ignorance of Linux is showing through
I had no issues with the Apple aluminum bt keyboard & magic mouse when paired with the internal bt or bt dongle on a notebook/netbook. But for a legacy desktop system that didn’t have bt and needed a bt dongle, the magic mouse worked fine. But the keyboard, that acted like a number pad and after reading this:
https://help.ubuntu.com/community/AppleKeyboard#Numlock%20on%20Apple%20Wireless%20Keyboard
the issue was the wired keyboard I still had connected had the number lock enabled. Disabling the number lock did the trick, after pairing the Apple bt devices, all of the keys function with the aluminum keyboard. I have the latest 2 battery alum bt keyboard and not the previous 3 battery alum bt keyboard.
I tried disconnecting the keyboard and going straight into Ubuntu with only a mouse, but it’s apparent that since I shutdown the system with the num lock enabled, that was a saved setting. Disabling the num lock and shutting down resolves that too.
I’m happy with it !