World Library  
Flag as Inappropriate
Email this Article


Article Id: WHEBN0001267101
Reproduction Date:

Title: Scancode  
Author: World Heritage Encyclopedia
Language: English
Subject: Keyboard layout, Keycode, Reference desk/Archives/Computing/2015 August 3, Keyboard controller (computing), Sharp QT-8D
Collection: Computer Keyboards, Data Transmission, Encodings
Publisher: World Heritage Encyclopedia


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.


  • Variants 1
  • Scancode sets 2
    • PC compatibles 2.1
    • USB 2.2
  • See also 3
  • References 4
  • External links 5


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.[1] 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.

Scancode sets

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.]

PC compatibles

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.

The IBM 3270 PC introduced its own set of scancodes ("set 3"), with a different key numbering and where a key release is indicated by an F0 prefix. For backward compatibility, the 3270 PC translated these to XT (set 1) scancodes using an add-on card and a BIOS extension. This set is used by Linux by default when it detects a PS/2 keyboard that can properly support scan code set 3.[2]

The IBM PC AT introduced the "AT" ("set 2") scancodes. On the 84-key AT keyboard these were largely a subset of set 3, with some differences caused by the revised layout (for example, the position and scancodes of the function keys changed). Keys added since the PC AT often have different scancodes in set 2 and set 3, and in set 2 frequently have an E0 or E1 prefix. Again, key release is indicated by an F0 prefix.

For computers since the IBM PC AT, the keyboard controller on the motherboard translates AT (set 2) scancodes into XT (set 1) scancodes in so called translation mode.[3] This translation can be disabled in pass-through-mode, allowing the raw scancodes to be seen.[4] Therefore, whether a software developer will encounter AT scancodes or XT scancodes on a modern PC-compatible depends on how the keyboard is being accessed.

A compliant PS/2 keyboard can be told to send scancodes in set 1, 2 or 3.

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


USB 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


  1. ^ For example, the traditional 12-key numeric keypad is scanned as 3 columns by 4 rows, requiring a total of 7 connections. Scanning each key separately would require 12 connections.
  2. ^
  3. ^ Keyboard scancodes (section 10, "Keyboard internal scancodes"), Andries Brouwer. Version 1.2e, 2004-05-20, accessed 2006-11-15.
  4. ^ Keyboard scancodes (section 11, "The AT keyboard controller"), Andries Brouwer. Version 1.2g, 2009-07-07, accessed 2010-07-18.

External links

  • Keyboard scancodes: written by Andries Brouwer
  • Interfacing the AT Keyboard: Detailed information on keyboard scancodes from
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.