Scancode
A number or bit array uniquely identifying a keyboard key.
A scancode—sometimes written as scan code—is a number or bit array that a keyboard protocol uses to identify a specific key on a keyboard. Keyboards typically send these codes to the computer so the system can update its internal keyboard state, which records which keys are currently held down. The details of how, when, and what scancodes are sent depend on the protocol in use. Some keyboard protocols update the internal state by other means, such as sending a bitmap that encodes whether each key is pressed or released. For example, a keyboard using the HID protocol with the Boot Protocol selected sends a bitmap for modifier keys (each bit representing one key’s state) along with a scancode array for the pressed keys that are not modifiers.
Historically, mapping key positions by row and column required less complex hardware, so using software or firmware to translate scancodes into text characters was cheaper than wiring the keyboard by character. That cost difference is no longer as significant, but many computer systems still use their traditional scancodes to maintain backward compatibility.
On IBM PC compatible computers, keyboards send a scancode when a key is pressed and another when it is released. The scancode sent on a key press is called the “make” scancode, and it differs from the “break” scancode sent on release. The standard also allows keyboards to generate typematic repeating keys by repeatedly sending the make scancode while a key is held down. Most character keys have a single-byte make scancode; keys with special functions use two- or three-byte scancodes, usually starting with the hexadecimal byte E0, E1, or E2. A few keys send longer scancodes that emulate a series of keys, making them easier for various software to process.
PC keyboards since the PS/2 standard support up to three scancode sets. A PS/2 compatible keyboard can be instructed to send scancodes in set 1, set 2, or set 3, though which sets are supported depends on the keyboard. The most common are the “XT” (set 1) scancodes, based on the 83-key keyboard of the IBM PC XT. These are mostly single bytes: the low 7 bits identify the key, and the most significant bit is clear for a key press (make) or set for a key release (break). Some additional keys have an E0 (or rarely, E1 or E2) prefix.
- Scancode sets on ps2 keyboards
- up to three (set 1, set 2, set 3)
- Common set
- XT (set 1) scancodes, based on the 83-key IBM PC XT
- Make scancode bit meaning
- most significant bit clear for press, set for release (set 1)
- Break prefix in set 3
- F0 prefix
- Translation mode
- keyboard controller translates set 2 to set 1 on modern PC compatibles
Lore & Background
Historically, mapping key positions by row and column required less complex computer hardware, so using software or firmware to translate scancodes to text characters was less expensive than wiring the keyboard by character. This cost difference is no longer as profound, but many computers still use traditional scancodes for backward compatibility.
On IBM PC compatible keyboards, a make scancode is sent when a key is pressed and a break scancode when released. Most character keys have a single-byte make scancode; special-function keys have 2- or 3-byte scancodes, often beginning with E0, E1, or E2. PC keyboards since the PS/2 support up to three scancode sets, with set 1 (XT) being most common. In set 1, the low 7 bits identify the key, the most significant bit is clear for press and set for release. Set 3, introduced by the IBM 3270 PC, uses an F0 prefix for key release. Set 2 (AT) was introduced with the IBM PC AT; on modern PCs, the keyboard controller can translate set 2 to set 1 in translation mode, or pass raw scancodes in pass-through mode.
USB keyboards use a new set of scancodes specified in the USB standard, recognized by all computers that support USB keyboards. Some virtual keyboards may not input scancodes but Unicode characters, though those attached via remote desktop software often do send scancodes.
Reader's Guide
Scancodes remain significant as the fundamental link between physical key presses and computer interpretation. The article notes that IBM PC compatible keyboards have used scancodes since the XT, with three defined sets (1, 2, 3) that maintain backward compatibility across decades of hardware. The translation mode in modern PC compatibles—where the keyboard controller converts set 2 to set 1—ensures that software expecting older scancodes continues to function. This legacy is so ingrained that Linux detects whether translation is active and selects the appropriate scancode set accordingly. The article also highlights that USB keyboards introduced a new scancode set, but the concept of uniquely identifying keys via scancodes persists. The ability to discover a key's scancode by holding it during boot (resulting in a 'stuck key' error message) demonstrates the low-level accessibility of scancodes. Overall, scancodes are a lasting protocol element that bridges physical keyboard hardware and operating system input handling, with their historical cost advantages now superseded by the need for compatibility.
Did You Know?
- On Windows 7, only one byte of the scancode appears in a 'stuck key' error message.
- The IBM 3270 PC introduced set 3 scancodes, which use an F0 prefix for key release.
- A keyboard using the HID Boot Protocol sends modifier key states as a bitmap alongside a scancode array of pressed keys.
More in Computer Keyboards 1-24
Spotted an error? Know more?
Reader corrections go straight into our review queue. Suggest an edit · How this site is sourced
