Remapping keys in X11
March 27, 2005
I have just figured out how to modify the X11 (X Windows) keymap.
The configuration of the keys is controlled by a file which is
parsed by a program called xmodmap. The file that specifies the key
mappings is best edited with a graphical tool called xkeycaps. This
tool has a button labelled “Write”, which saves the
mappings to a file whose filename is appended with the hostname of
your computer, e.g. it might be called
“~/.Xmodmap-deathstar”, where “deathstar”
is the hostname. What you then need to do is to make sure this file
is parsed by xmodmap each time you login to your computer. You do
this by putting a line in your login script that runs xmodmap. On
SuSE Linux, this file is called .profile (in your home directory).
xkeycaps will tell you what to put in the login script, but it will
be something like “xmodmap ~/.Xmodmap-`uname -n`”,
which works out what your hostname is (rather than you having to
hard code it).
Below is a description of what I have remapped—so that when I
screw up and need to re-do the above I can “remember”
what my new keyboard looks like—you might also find
inspiration for your own mapping (note: I am in the UK and we have
slightly different keyboard layouts to those in the US and
elsewhere):
- Doing Shift+’ now produces the double quotes character
("),as on my iBook, which has a more US-style keyboard layout
(which is more logical in some ways).
- Shift+2 now produces the @ symbol (again, like my iBook)
- The (parentheses) have been moved off the 9 and 0 keys. It
doesn’t make sense to have to shift to use these common
characters. They are now on the (unshifted) “[{” and
“}]” keys. These keys are easy to get to, and their
default characters are less-frequently used compared to the
parentheses characters.
- Shift+9 and Shoft+0 now produce { and }. I use these characters
in Matlab code, but not as much as the parentheses keys. I
don’t write much C or C++.
- Shift+“[{” and Shift+“}]” now produces
“[” and “]”. I use these characters
reasonably frequently in Matlab, but less frequently than the
parentheses characters, hence shifting is OK.
- The * has been moved off Shift+8 and onto the ` (grave) key
(which is under the Esc key for us UK people). I’m trying to
learn Lisp, which seems to use the * character quite a bit. Also,
when doing multiplication in Matlab (or any other programming
language), it makes sense not to have to shift to get the symbol.
The ` (grave) character is now on Shift+8.
- Caps Lock now does the same as Ctrl (who uses Caps Lock these
days?). I did this using Gnome’s keyboard preferences, not
xkeycaps (though I think you can).
I wonder how many bugs I will introduce as a result of these
changes :-}