Scancode
The scancode is a sequence of numbers that the keyboard sends to the computer to notify it which keys were pressed or released.
Some keyboards send a key to be pressed multiple times while the key is not released.
Since different keyboards have different layouts, the scancode is somewhat device dependent.
Keycode
The keyboard driver interprets the scancode and generates (device independent) keycodes.
A keycode is a number in the range between 8 and 255 which represents a physical (or logical) key.
The kernel parses the stream of scancodes and maps them to a series of keycodes (key press/release events).
showkey
apparently is also able to display those keycodes.
In a console, the mapping can be viewed with
getkeycodes
.
X produces a keycode when a key is pressed and another when the key is released again.
Keysym
Depending on which
Modifier keys are pressed, the keycodes are mapped to keysyms.
A keysym is a 32-bit integer of which the the three most significant bits are always 0, so that the number space is 29 bits.
A
keysym is an encoding of a symbol on the cap of a kay; it represents a keyboard action. Each key can be bound to up to 256 keysyms (see
keymap - keycode definition)
Such actions can be
- outputting character codes
- character sequences
- switching consoles
- switching keymaps
- booting the machine
- etc
The action chosen is dependent on the
modifier keys pressed concurrently with the key.
In a console, the complete list can be queried with
dumpkeys -l
With
xev
, it possible to display keycode and keysym:
xev -event keyboard
.
Apparently, there is a xcb-util-keysyms package that contains a library for handling standard X key constants and conversion to/from keyboards.
Special keysyms
There are two special keysyms: NoSymbol
and VoidSymbol
which indicate the absence of symbols.
Names of keysyms
A possible name for a keysym is for example CAPS LOCK
.
X11
The X11 standard defines keysym codes. these codes are 29 bit integer values (that identify characters of functions for a keyboard-key).