April 21, 2009

Apple Keyboard on Linux

Filed under: Technical — Tags: , , — delx @ 5:20 pm

The Apple aluminium keyboards are very nice. I recently bought one for an Ubuntu Linux machine, and it requires some special configuration to work as expected.

This post describes how to fix the function keys and swap command (windows or ’super’) keys with the alt (or option) keys.

Apple Aluminium Keyboard

This command will fix the function keys, it saves you pressing fn-F1 whenever you want F1. The first command is for older kernels, the second is for version 2.6.28 or later.

# echo 2 > /sys/module/hid/parameters/pb_fnmode
# echo 2 > /sys/module/hid_apple/parameters/fnmode

Then add that line to your /etc/rc.local file, somewhere before the exit 0 at the end, so that it gets run on startup.

Next to swap the Command/Alt keys using xmodmap. I’m aware you can do this from the Gnome Keyboard Settings panel, but I’ve found this method works better. Particularly when combined with synergy.

Create a file called ~/.xmodmaprc with this inside:

clear mod1
keycode 115 = Alt_L
keycode 116 = Alt_R
keycode 64 = Super_L
keycode 113 = Super_R
add mod1 = Alt_L Alt_R

On another computer I’ve found this worked:

clear mod1
keycode 133 = Alt_L
keycode 134 = Alt_R
keycode 64 = Super_L
keycode 108 = Super_R
add mod1 = Alt_L Alt_R

Now run to activate the new keys, run:

$ xmodmap ~/.xmodmaprc

Don’t forget to add it to your list of startup programs. If you’re using Gnome, look at System->Preferences->Startup Applications
Otherwise you can just add it to ~/.xsession

To find the keycodes above I used the xev program. Try running it from a console. It shows you all X11 events that the xev window receives, including key presses/releases.

1 Comment »

  1. It seems that under newer kernels (I am using 2.6.28), you need to change the file in /sys that you change. You must now use “echo 2 > /sys/modules/hid_apple/parameters/fnmode”

    It also seems to require a different xmodmaprc file. Mine is:

    remove mod1 = Alt_L Alt_R
    keycode 64 = Super_L
    keycode 133 = Alt_L
    keycode 134 = Alt_R
    keycode 108 = Super_R
    add mod1 = Alt_L Alt_R
    

    Comment by Greg Darke — May 24, 2009 @ 10:12 pm

RSS feed for comments on this post. TrackBack URL

Leave a comment