*** Welcome to piglix ***

Scancode


A scancode (or scan code) is the data that most computer keyboards send to a computer to report which keys have been pressed. A number, or sequence of numbers, is assigned to each key on the keyboard.

Mapping key positions by row and column requires less complex computer hardware; therefore, in the past, using software or firmware to translate the scancodes to text characters was less expensive than wiring the keyboard by text character. This cost difference is not as profound as it used to be. However, many types of computers still use their traditional scancodes to maintain backward compatibility.

Some keyboard standards include a scancode for each key being pressed and a different one for each key being released. In addition, many keyboard standards (for example, IBM PC compatible standards) allow the keyboard itself to generate "typematic" repeating keys by having the keyboard itself generate the pressed-key scancode repeatedly while the key is held down, with the release scancode sent once when the key is released.

On some operating systems one may discover a key's downpress scancode by holding the key down while the computer is booting. With luck, the scancode (or some part of it) will be specified in the resulting "stuck key" error message. [Note: On Windows 7 only one byte of the scancode appears.]

Scancodes on IBM PC compatible computer keyboards are sets of 1 to 3 bytes which are sent by the keyboard. Most character keys have a single byte scancode; keys that perform special functions have 2-byte or 3-byte scancodes, usually beginning with the byte (in hexadecimal) E0, E1, or E2. In addition, a few keys send longer scancodes, effectively emulating a series of keys to make it easier for different types of software to process.

PC keyboards since the PS/2 keyboard support up to three scancode sets. The most commonly encountered are the "XT" ("set 1") scancodes, based on the 83-key keyboard used by the IBM PC XT and earlier. These mostly consist of a single byte; the low 7 bits identify the key, and the most significant bit is clear for a key press or set for a key release. Some additional keys have an E0 (or rarely, E1 or E2) prefix. These were initially assigned so that ignoring the E0 prefix (which is in the key-up range and thus would have no effect on an operating system that did not understand them) would produce reasonable results. For example the numeric keypad's Enter key produces a scancode of E0 1C, which corresponds to the regular Enter key's scancode of 1C.


...
Wikipedia

...