What is raw keyboard mode?

When you press a key on your keyboard, it sends a numeric code to the computer, called a scan code. The scan code tells the computer which key was pressed; for example, on a typical US keyboard, the A key sends the scan code 30 when you press it (and 158 when you release it). The keyboard driver reports these codes directly to applications when the keyboard is in raw mode (“raw” means unprocessed, straight off-the-keyboard). A few programs use raw mode and do their own keyboard processing; the X server is the most prominent one.

Most programs expect that when you press the A key, the program reads the character a (ASCII 97), and that when you press Shift+A the program reads A (ASCII 65), and when you press Ctrl+A the program reads the Ctrl+A character (ASCII 1). Keys that don't have associated characters send escape sequences, e.g. \e[A for Left, where \e is the ESC character (ASCII 27). The keyboard driver performs this translation when the keyboard is in ASCII mode, also called XLATE mode (short for “translate”). XLATE mode lets applications do character input, at the cost of not having access to such nuances as “Left Shift key pressed” or Ctrl+Shift+A as distinct from Ctrl+A.

The kbd_mode lets you switch between modes, and shows the current mode if you invoke it without any argument.

The magic SysRq key combinations are meant to recover from various nasty situations. One of the key combinations is Alt+SysRq+K to kill all programs on the current virtual console; if that program put the keyboard in raw mode, then you won't be able to type at the login prompt (which will often appear, depending on your system configuration). Pressing Alt+SysRq+R restores the usual (outside X) ASCII mode where you can type characters.


You can define which type of code your keyboard sends. This is done via the keyboard mode. You can change the mode of a keyboard with kbd_mode.

These are the options from the manpage:

   -s: scancode mode (RAW),
   -k: keycode mode (MEDIUMRAW),
   -a: ASCII mode (XLATE),
   -u: UTF-8 mode (UNICODE).

Its much easier for a developer to catch key events like left shift key pressed, if he can simply get the scancodes of the pressed keys.