Swapping keyboard keys on X11 with xmodmap

For the past year I’ve been working on a Mac Mini, but it didn’t really work for me, so I’ve moved back to my trusty Linux box which is a much better place to run the open source software that I use.

One of the things that I do like about the Mac is the keyboard, and so I’ve now plugged it into my linux box, and thrown out the clunky PC keyboard.

Linux is apparently ready for this: There is already a keyboard type of Macintosh Aluminium.

However, for some reason the ±§ key and the ~` key are swapped, which is irritating as I often type ~ and `.

No problem: I can just use xmodmap to swap them around.

First figure out the current configuration of those keys:

$ xmodmap -pke

reveals …

.
.
keycode 94 = section plusminus grave notsign notsign notsign bar bar
.
.
keycode 49 = grave asciitilde backslash bar bar brokenbar bar brokenbar

I can now create a ~/.Xmodmap file to swap them around as follows:

keycode 49 = section plusminus grave notsign notsign notsign bar bar
keycode 94 = grave asciitilde backslash bar bar brokenbar bar brokenbar

Then I can run the file:

$ xmodmap ~/.Xmodmap

The keys are now working correctly.

Additionally, every time that I login, the .Xmodmap file will be run and so my keys will always be correct.

Date: April 17, 2015

Category: Linux Admin Tips

Author: John Taylor

Respond To This Post: