Scancode
Encyclopedia
A scancode is the data that most computer keyboard
s 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.
; 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.
keyboards are sets of 1 to 3 byte
s 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)
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
Later additions (such as the Windows keys on many keyboards) have not followed this pattern.
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.
keyboards use a new set of scancodes, mostly specified in the USB standard. All computers that recognize USB keyboards recognize these new scancodes.
Computer keyboard
In computing, a keyboard is a typewriter-style keyboard, which uses an arrangement of buttons or keys, to act as mechanical levers or electronic switches...
s send to a computer
Computer
A computer is a programmable machine designed to sequentially and automatically carry out a sequence of arithmetic or logical operations. The particular sequence of operations can be changed readily, allowing the computer to solve more than one kind of problem...
to report which keys have been pressed. A number, or sequence of numbers, is assigned to each key on the keyboard.
Variants
Mapping key positions by row and column requires less complex computer hardwareComputer hardware
Personal computer hardware are component devices which are typically installed into or peripheral to a computer case to create a personal computer upon which system software is installed including a firmware interface such as a BIOS and an operating system which supports application software that...
; therefore, in the past, using software or firmware
Firmware
In electronic systems and computing, firmware is a term often used to denote the fixed, usually rather small, programs and/or data structures that internally control various electronic devices...
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
Backward compatibility
In the context of telecommunications and computing, a device or technology is said to be backward or downward compatible if it can work with input generated by an older device...
.
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
IBM PC compatible
IBM PC compatible computers are those generally similar to the original IBM PC, XT, and AT. Such computers used to be referred to as PC clones, or IBM clones since they almost exactly duplicated all the significant features of the PC architecture, facilitated by various manufacturers' ability to...
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.
PC compatibles
Scancodes on IBM PC compatibleIBM PC compatible
IBM PC compatible computers are those generally similar to the original IBM PC, XT, and AT. Such computers used to be referred to as PC clones, or IBM clones since they almost exactly duplicated all the significant features of the PC architecture, facilitated by various manufacturers' ability to...
keyboards are sets of 1 to 3 byte
Byte
The byte is a unit of digital information in computing and telecommunications that most commonly consists of eight bits. Historically, a byte was the number of bits used to encode a single character of text in a computer and for this reason it is the basic addressable element in many computer...
s 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
.Later additions (such as the Windows keys on many keyboards) have not followed this pattern.
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
Backward compatibility
In the context of telecommunications and computing, a device or technology is said to be backward or downward compatible if it can work with input generated by an older device...
, the keyboard controller on the motherboard
Motherboard
In personal computers, a motherboard is the central printed circuit board in many modern computers and holds many of the crucial components of the system, providing connectors for other peripherals. The motherboard is sometimes alternatively known as the mainboard, system board, or, on Apple...
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
IBM 3270 PC
The IBM 3270 PC , released in October 1983, was an IBM PC XT containing additional hardware which could emulate the behaviour of an IBM 3270 terminal...
, 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.
key | set 1 (IBM PC XT) | set 2 (IBM PC AT) | set 3 (IBM 3270 PC IBM 3270 PC The IBM 3270 PC , released in October 1983, was an IBM PC XT containing additional hardware which could emulate the behaviour of an IBM 3270 terminal... ) |
|||
---|---|---|---|---|---|---|
press | release | press | release | press | release | |
A (normal letter) | 1E |
9E |
1C |
F0 1C |
1C |
F0 1C |
Return / Enter Carriage return Carriage return, often shortened to return, refers to a control character or mechanism used to start a new line of text.Originally, the term "carriage return" referred to a mechanism or lever on a typewriter... (main keyboard) |
1C |
9C |
5A |
F0 5A |
5A |
F0 5A |
Enter Enter key In computer keyboards, the enter key in most cases causes a command line, window form, or dialog box to operate its default function... (numeric keypad Numeric keypad A numeric keypad, numpad or tenkey for short, is the small, palm-sized, seventeen key section of a computer keyboard, usually on the very far right. The numeric keypad features digits 0 to 9, addition , subtraction , multiplication and division symbols, a decimal point and Num Lock and Enter keys... ) |
E0 1C |
E0 9C |
E0 5A |
E0 F0 5A |
79 |
F0 79 |
Left Windows key Windows key The Windows logo key—also known as the Windows key, the home key, the meta key, the start key, MOD4, or the flag key —is a keyboard key which was originally introduced on the Microsoft Natural keyboard before the release of Windows 95. This key became a standard key on PC keyboards... |
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 |
USB
USBUniversal Serial Bus
USB is an industry standard developed in the mid-1990s that defines the cables, connectors and protocols used in a bus for connection, communication and power supply between computers and electronic devices....
keyboards use a new set of scancodes, mostly specified in the USB standard. All computers that recognize USB keyboards recognize these new scancodes.
See also
- Dead keyDead keyA dead key is a special kind of a modifier key on a typewriter or computer keyboard that is typically used to attach a specific diacritic to a base letter. The dead key does not generate a character by itself but modifies the character generated by the key struck immediately after...
- Meta keyMeta keyThe meta key is a special key on MIT keyboards, such as the space-cadet keyboard, and on Sun Microsystems keyboards, marked as a solid diamond.The key is similar in function to the Macintosh's command key, which has the same location...
- Keyboard layoutKeyboard layoutA keyboard layout is any specific mechanical, visual, or functional arrangement of the keys, legends, or key–meaning associations of a computer, typewriter, or other typographic keyboard....
- Keyboard technologyKeyboard technologyThere are many types of keyboards, usually differentiated by the switch technology employed in their operation. Keyboards are defined by the number of highly durable switches that are incorporated into the system...
- TypeaheadTypeaheadTypeahead is a feature of computers and software that enables users to continue typing regardless of program or computer operation—the user may type in whatever speed he or she desires, and if the receiving software is busy at the time it will be called to handle this later...
External links
- Keyboard scancodes: written by Andries Brouwer
- Interfacing the AT Keyboard: Detailed information on keyboard scancodes from beyondlogic.org