Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Scancode
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Data sent by computer keyboard keypress}} {{refimprove|date=October 2011}} A '''scancode''' (or '''scan code''') 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. == Variants == 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.<ref>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.</ref> 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 [[computer keyboard|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) <code>E0</code>, <code>E1</code>, or <code>E2</code>. 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 <code>E0</code> (or rarely, <code>E1</code> or <code>E2</code>) prefix. These were initially assigned so that ignoring the <code>E0</code> 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 <code>E0 1C</code>, which corresponds to the Return key's scancode of <code>1C</code>. 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 <code>F0</code> 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.<ref>{{Citation | url = https://github.com/torvalds/linux/blob/master/drivers/input/keyboard/atkbd.c | first = Vojtech | last = Pavlik | title = AT and PS/2 keyboard driver (atkbd.c) | work = Torvalds/Linux | via = [[GitHub]] | date = 18 February 2022}}</ref> 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 key]]s changed). Keys added since the PC AT often have different scancodes in set 2 and set 3, and in set 2 frequently have an <code>E0</code> or <code>E1</code> prefix. Again, key release is indicated by an <code>F0</code> 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''.<ref name="aeb10">{{Citation | url = http://www.win.tue.nl/~aeb/linux/kbd/scancodes.html | title = Keyboard scancodes | chapter-url = http://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html | chapter = Section 10, "Keyboard internal scancodes" | first = Andries | last = Brouwer | author-link = Andries Brouwer | edition = Version 1.2e | date = 2004-05-20 | access-date = 2006-11-15}}</ref> This translation can be disabled in ''pass-through-mode'', allowing the raw scancodes to be seen.<ref name="aeb11">{{Citation | url = http://www.win.tue.nl/~aeb/linux/kbd/scancodes.html | title = Keyboard scancodes | chapter-url = http://www.win.tue.nl/~aeb/linux/kbd/scancodes-11.html |chapter = Section 11, "The AT keyboard controller" | first = Andries | last = Brouwer | author-link = Andries Brouwer | edition = Version 1.2g | date = 2009-07-07 | access-date = 2010-07-18 }}</ref> 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. {| class="wikitable" |+ Example PC compatible (IBM PS/2) scancodes ! rowspan=2 | key ! colspan=2 | set 1 ([[IBM PC XT]]) ! colspan=2 | set 2 ([[IBM PC AT]]) ! colspan=2 | set 3 ([[IBM 3270 PC]]) |- ! press ! release ! press ! release ! press ! release |- | {{Key press|A}} (simple letter) | <code>1E</code> | <code>9E</code> | <code>1C</code> | <code>F0 1C</code> | <code>1C</code> | <code>F0 1C</code> |- | {{Key press|Enter}} (main keyboard) | <code>1C</code> | <code>9C</code> | <code>5A</code> | <code>F0 5A</code> | <code>5A</code> | <code>F0 5A</code> |- | {{Key press|Enter}} ([[numeric keypad]]) | <code>E0 1C</code> | <code>E0 9C</code> | <code>E0 5A</code> | <code>E0 F0 5A</code> | <code>79</code> | <code>F0 79</code> |- | Left {{Key press|Win}} ([[Windows key]]) | <code>E0 5B</code> | <code>E0 DB</code> | <code>E0 1F</code> | <code>E0 F0 1F</code> | <code>8B</code> | <code>F0 8B</code> |- | Right {{Key press|Win}} | <code>E0 5C</code> | <code>E0 DC</code> | <code>E0 27</code> | <code>E0 F0 27</code> | <code>8C</code> | <code>F0 8C</code> |} === USB === {{See|USB human interface device class}} [[Universal Serial Bus|USB]] keyboards use a new set of scancodes, mostly specified in the USB standard. All computers that recognize USB keyboards recognize these new scancodes.<ref name="msusb13a">{{ Citation | url = http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc | title = Microsoft Keyboard Scan Code Specification | chapter = Appendix C, "USB Keyboard/Keypad Page (0x07)" | author = [[Microsoft Corporation]] |edition = Revision 1.3a | date = 2000-03-16 | access-date = 2018-10-13 }}</ref> == See also == * [[Dead key]] * [[Meta key]] * [[Keyboard layout]] == References == {{reflist}} == External links == * [http://www.win.tue.nl/~aeb/linux/kbd/scancodes.html Keyboard scancodes]: written by Andries Brouwer * [https://web.archive.org/web/20000408154611/http://www.beyondlogic.org/keyboard/keybrd.htm Interfacing the AT Keyboard]: Detailed information on keyboard scancodes from beyondlogic.org [[Category:Computer keyboards]] [[Category:Data transmission]] [[Category:Encodings]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Citation
(
edit
)
Template:Key press
(
edit
)
Template:Refimprove
(
edit
)
Template:Reflist
(
edit
)
Template:See
(
edit
)
Template:Short description
(
edit
)