Scancode - Scancode Sets - PC Compatibles

PC Compatibles

Scancodes on IBM PC compatible 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-compatibles have used three scancode sets. The most commonly encountered are the "XT" ("set 1") scancodes, 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.

The IBM PC AT introduced the "AT" ("set 2") scancodes, with a different key numbering and where a key release is indicated by an F0 prefix. For backward compatibility, the keyboard controller on the motherboard translates these into XT (set 1) scancodes. This translation can be disabled, allowing the raw scancodes to be seen. Therefore, whether an engineer will encounter AT scancodes or XT scancodes on a modern PC-compatible depends on how the keyboard is being accessed.

The set 2 scancodes are used by most keyboards since the PC AT, including PS/2 keyboards. "Set 3", a subset of the scancodes used by the 122-key keyboard on the IBM 3270 PC, also exists, but is rarely used.

To add to the confusion, the keyboard can be told to send scancode set 1, 2 or 3. The most common mode of operation on a PC compatible computer is for the keyboard to send set 2, which is translated by the keyboard controller into set 1.

Example PC compatible (IBM PS/2) scancodes
key set 1 (IBM PC XT) set 2 (IBM PC AT) set 3 (IBM 3270 PC)
press release press release press release
A (normal letter) 1E 9E 1C F0 1C 1C F0 1C
Return / Enter (main keyboard) 1C 9C 5A F0 5A 5A F0 5A
Enter (numeric keypad) E0 1C E0 9C E0 5A E0 F0 5A 79 F0 79
Left Windows key E0 5B E0 DB E0 1F E0 F0 1F 8B F0 8B
Right Windows key E0 5C E0 DC E0 27 E0 F0 27 8C F0 8C

Read more about this topic:  Scancode, Scancode Sets