2011-09-01

Apple Keyboard on linux

To be able to use an Apple keyboard (MB110D/A) on a linux system, the correct layout must be set first. Select the corresponding in the Keyboard Preferences. In this case Germany Macintosh is added to the layouts list.
Keyboard model should be Apple.


Unfortunately, the keys [^/°] and [] remain reversed. To fix this the key codes have the be reassigned:

1) Find out the keycode
With help of the programm xev the keycode can be figured out. Start the programm as follows and press the keys [^/°] and [] afterwards. The keycodes should be displayed.
$ xev | grep keycode
    state 0x10, keycode 94 (keysym 0xfe52, dead_circumflex), same_screen YES,
    state 0x10, keycode 94 (keysym 0xfe52, dead_circumflex), same_screen YES,
    state 0x10, keycode 49 (keysym 0x3c, less), same_screen YES,
    state 0x10, keycode 49 (keysym 0x3c, less), same_screen YES,
So we need to fix the assignment for the keycodes 94 and 49.

2) Show current key assignment
The current key assignment can be displayed using xmodmap.
$ xmodmap -pke | grep " 94"
keycode  94 = less greater less greater bar brokenbar bar
$ xmodmap -pke | grep " 49"
keycode  49 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032 
Here you can already see the problem. On the button [^ / °] with keycode 94 are the signs for smaller, bigger, ...

3) Change key assignment
With xmodmap the key assignement can be changed.
$ xmodmap -e 'keycode 49 = less greater less greater bar brokenbar bar'
$ xmodmap -e 'keycode 94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032'
However, this change only lasts until the next reboot. In order to implement this change permanent or restore after a reboot, the new assignments must be stored in the file ~/.Xmodmap.

$ xmodmap -pke | grep " 49" >> ~/.Xmodmap 
$ xmodmap -pke | grep " 94" >> ~/.Xmodmap 
The file should look like this now:
keycode  94 = dead_circumflex degree dead_circumflex degree U2032 U2033 U2032
keycode  49 = less greater less greater bar brokenbar bar