Search notes:

Keyboard

Some interesting/important keyboards

PC/XT Keyboard (1981)

The PC/XT keyboard has 83 keys and was introduced 1981 along with the IBM PC (Model 5150)
In order to faciliate internationalization of the IBM PC, this keyboard was the first one to send scancodes rather than ASCII codes to the computer.
The PC/XT keyboard was named after the IBM PC/XT (1983) which had the same keyboard as the Model 5150.

PC/AT Keyboard (1984)

The PC/AT keyboard added the SysRq key (see also here) so that this keyboard features 84 keys.
The scan codes ware different from the ones in the PC/XT keyboard.
For compatibility reasons, the Intel 8042 chip was sometimes(?) used to translate PC/AT scan codes to PC/XT keyboards.
This keyboard was also to communicate bi-directionally (LEDs).

MF2 Keyboard (1986)

MF stands for multi functional. This keyboard has between 101 and 105(?) keys.

Scancodes, keycodes and keysyms

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.
In a virtual console, these scancodes can be displayed with showkey -s.

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 X, the translation table from (evdev?) scancocdes to keycodes seems to be stored in /usr/share/X11/xkb/keycodes/evdev
In a console, the mapping can be viewed with getkeycodes.
In Linux, this seems to happen in drivers/tty/vt/keyboard.c.
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
In X, this is done by xmodmap.
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).
These X11 keysym codes have (mnemonic) names which are found in X11/keysymdef.h (without XK_ prefix), and is possibly supplemented by /usr/share/X11/XKeysymDB.

Modifier keys

Keys such as shift, ctrl, alt (etc?) are called modifier keys. These are used to change the meaning of other keys.
XKB recognizes 8 modifier keys: Control, Shift, Lock, Mod1, Mod2, Mod3, Mod4 and Mod5. The Alt key(s) are mapped to one (or more?) of the Mod keys.
Modifier keys can be combined (alt+ctrl etc).

Change keyboard layout

Windows

swap-keys.c, a small C program that swap the Esc and Caps Lock keys and assigns the right ctrl key to the right alt key.
A similar program is SwapKeys.cs, but written in C#.
In Windows, the installed keyboard layouts are listed in the registry under HKLM\SYSTEM\CurrentControlSet\Control\Keyboard Layout\DosKeybCodes.

Linux

The language keyboard layout files are under /usr/share/X11/xkb/symbols.

Keyboard modifiers

Shift, AltGr, Control, Alt, ShiftL, ShiftR, CtrlL, CtrlR, CapsShift

Number of keys

The number of keys apparently defines the keyboard model (pc104, pc105 …, compare /usr/share/X11/xkb/rules/xorg.lst)
The 105 key keyboard (apparently european layout) seems to be like the 104 key keboard (us layout) with an additional key between the left shift key and the z (or y) key.

Scroll Lock

Some laptops and keyboard don't have a scroll lock key. Methods to simulate this key include:
On Windows, osk.exe might also be used to enter or leave scroll-lock mode.

Configuring/modifying the keyboard layout

swap_keys.c
SwapKeys.cs
Python: Mapping my keyboard with evdev
caps2esc
Interception is a Windows driver (dual licensed).

See also

keymap
xkbcomp
/usr/share/X11/xkb/rules/xorg.lst
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout, Registry: HKEY_CURRENT_USER\Keyboard Layout\Preload
Windows: osk.exe and kbd*.dll under %SYSTEMROOT%\System32
control.exe intl.cpl,,2
The property KeyboardLayoutId of the System.Globalization.CultureInfo object returned by the PowerShell cmdLet get-culture.

Index