Linux : Modify key mappings in Linux with xmodmap

This page last changed on Nov 04, 2008 by Kees de Kooter


I just bought a small portable keyboard that unfortunately has only one control key. On the right side the contol position is taken by a key with the symbols \ and |. I want to map this key to be the right control key. Here is how I did it. This is tested with Ubuntu 8.04 aka "Hardy Heron".

Use xev to find keycode

The xev utility (X Event Tester) writes information of the key pressed to stdout. In my case it displays:

KeyRelease event, serial 31, synthetic NO, window 0x2a00001,
    root 0x87, subw 0x0, time 14383001, (88,-7), root:(1424,253),
    state 0x0, keycode 94 (keysym 0x3c, less), same_screen YES,
    XLookupString gives 1 bytes: (3c) "<"
    XFilterEvent returns: False

So the keycode to be mapped is 94.

Execute xmodmap commands

Key mappings can be modified with the xmodmap utility.

xmodmap -e "remove Control = Control_R"
xmodmap -e "keycode 94 = Control_R"
xmodmap -e "add Control = Control_R"

Put xmodmap commands in a script

In order to apply the mappings every time you start an X session you can put the commands in a file called .Xmodmap, to be placed in the home directory. This is what it looks like:

remove Control = Control_R
keycode 94 = Control_R
add Control = Control_R


This solution does not seem to work in Ubuntu 8.10. Working on a fix!!


Somehow my newly mapped ctrl key does not work in conjunction with the shift key. This has to be fixed.

Other useful mappings

  • disable caps lock key: xmodmap -e "remove Lock = Caps_Lock"