Xmodmap

From wikinotes

Xmodmap is a tool that lets you customize your keyboard/mouse mappings within in xorg display servers.
I use xmodmap to handle different keyboards/mice, or disable the keyboard altogether.

Documentation

Locations

~/.Xmodmap User keybindings

KeyNames

Generally key-names are more consistent than their key-codes.

Look up what your keyboard registers for a button press using xev.

Usage

Grabbing Keycodes

xev                   # get keycodes for keyboard buttons (raw)
xbindkeys -k          # get keycode for single key
xbindkeys --multikey  # get keycode for multikey

See xbindkeys and xev for more details.

Binding Keycodes

xmodmap -pke  # print mappings

# run xmodmap command to change keybindings interactively
xmodmap -e 'keycode 66 = Control_L'

# bind mouse horizontal scrolling to vertical
xmodmap -e "pointer = 1 2 3   10 11   6 7 8 9   5 4   12 13 14 15 16 17 18 19 20 21"