| previous | contents | up | next |
The program to do this is xmodmap. It is included as part of the standard X distribution. Though swapping the Ctrl and Caps Lock keys is its most common use, xmodmap is actually a general-purpose keymap-editing tool. It can be used, for instance, to remap an entire keyboard from QWERTY to Dvorak style. It can even change the mappings of mouse buttons.
xmodmap works by reading a file of encoded operations,
each of which makes or
unmakes a binding between a key on the keyboard and the symbol it
should generate. The name of the file is arbitrary. The program
must be called once per X login, so users typically include a line
like xmodmap my_style_file in their
.xsession or .xinitrc.
The canonical .Xmodmap file for swapping Ctrl and Caps Lock reads as follows:
remove Lock = Caps_LockThe only problem with this file is that it swaps the two keys unconditionally, so that it will fix a keyboard with the "wrong" key placement, but will also foul up a keyboard with the "right" placement. If you frequently move among machines with different keyboards, this behavior can be very annoying. The simplest solution is to set both keys to emit the Control symbol. Caps Lock is almost never useful, except to people in chat rooms with very bad manners. To achieve this effect, use the following as the contents of the xmodmap input file:
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Caps_Lock
add Control = Control_L
remove Lock = Caps_Lock
keysym Caps_Lock = Control_L
add Control = Control_L
| previous | contents | up | next |