Skip to Content

How to disable annoying keys in X

Alaa's picture

the idea is very simple, we find out what the keycode of the annoying key is, then we use xmodmap to remap it to a new harmless or useless meaning.

you make a file called masalan ~/.xmodmap

in ~/.xmodmap you need to make entries that look like this

keycode 111 = XF86Excel

on the left is the X specific keycode generated by this key, and on the right is the symbolic keyname X will assign to this keycode.

you can find out the keycode by running xev

xev catches any X events when its in focus and writes what happens on the terminal, put the focus on the xev window and press your key you'll see lines that look like

  1. xev
KeyPress event, serial 28, synthetic NO, window 0x2a00001, root 0x71, subw 0x2a00002, time 74933419, (53,51), root:(57,68), state 0x0, keycode 111 (keysym 0xff61, Print), same_screen YES, XKeysymToKeycode returns keycode: 92 XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False KeyRelease event, serial 28, synthetic NO, window 0x2a00001, root 0x71, subw 0x2a00002, time 74933496, (53,51), root:(57,68), state 0x0, keycode 111 (keysym 0xff61, Print), same_screen YES, XKeysymToKeycode returns keycode: 92 XLookupString gives 0 bytes:

the symbolic keynames are all mentioned in the file /usr/X11R6/lib/X11/XKeysymDB

to completly disable a key use a keysym you're unlikely to ever need like the microsoft specific multimedia keys.

you can use the same technique to modify your keyboard in anyway (disable annoying hindi numerals, stop caps lock etc).

keycode 111 is the keycode of printscreen on my pc, the above line in ~/.xmodmap is enough to stop it

when you're done editing ~/.xmodmap you need to run

  1. xmdomap ~/.xmodmap

    this loads the new keymap, if the behavior is right you want to configure your system so that it runs xmodmap everytime you run X (you figure out how).



Dr. Radut | book