Scancode
A scancode is in strict terms an index that corresponds to the position a key has in a keyboard's internal keyboard matrix.
In IBM PC parlance, the term is also used for keys over the wire and within operating systems — because originally the mapping was direct to the matrix. It is also often sloppily used to name entire key event codes, or code sequences.
Most operating systems outside the PC use the term key code or virtual key code for key numbers. In USB parlance, the term for key number is usage code, and these are grouped in code pages. USB's Human Interface Device (HID) subprotocol uses usage codes not just for keys but for all types of controls and e.g. logical grouping and for signalling error conditions. Because USB HID sends status reports (not events), a key is represented by its usage code being either present (or bit set) or not present (or bit cleared).
Contents
IBM PC scancodes
Scancodes in Set 1 were used over the XT keyboard interface. They are still in use internally on systems with IBM PC lineage such as MS Windows and Linux ("raw mode").
Scancodes in Set 2 are used in the protocol used by the AT and PS/2 interfaces.
Scancodes in Set 3 are used in the keyboard protocol for terminals from IBM.
History
The IBM PC/XT protocol's scancodes corresponded directly to key positions when scanning the original IBM PC/XT keyboard's matrix. A single bit in the byte sent over the wire distinguishes between a key press (make) or key release event (break). Raw scancode bytes were delivered to programs by the BIOS.
The later protocol used by AT and PS/2 interfaces uses the different set 2 of code sequences over the wire. For the IBM PC/AT to remain backwards-compatible, XT scancodes were not only presented to programs by the BIOS but there was also a special microcontroller which converted the new Set 2 codes back to the old Set 1 codes for badly written programs that accessed the hardware directly.
However, with this backwards compatibility came added complexity. The IBM Enhanced Keyboard (Model M) introduced even more additional keys. Pressing some keys can produce quite long sequences to be sent, especially with modifiers. Therefore, IBM introduced the cleaner "Set 3" set of codes, also with some more capabilities. Some IBM keyboards are able to switch between different code sets on command from the host. [1]
The Set 3 did however not catch on outside IBM and was used almost only for terminal keyboards.
USB HID Usage Codes
Keyboard page (0x07)
Y = Part of official spec
T = Tested working but not in spec
<blank> = Not part of spec , not tested
USB | OS support | |||
---|---|---|---|---|
Code | Key Name | PC/MS Windows | Macintosh | UNIX/Linux |
00 | Reserved | Y | Y | Y |
01 | Keyboard ErrorRollOver[Notes 1] | Y | Y | Y |
02 | Keyboard POSTFail[Notes 1] | Y | Y | Y |
03 | Keyboard ErrorUndefined[Notes 1] | Y | Y | Y |
04 | Keyboard a and A | Y | Y | Y |
05 | Keyboard b and B | Y | Y | Y |
06 | Keyboard c and C | Y | Y | Y |
07 | Keyboard d and D | Y | Y | Y |
08 | Keyboard e and E | Y | Y | Y |
09 | Keyboard f and F | Y | Y | Y |
0a | Keyboard g and G | Y | Y | Y |
0b | Keyboard h and H | Y | Y | Y |
0c | Keyboard i and I | Y | Y | Y |
0d | Keyboard j and J | Y | Y | Y |
0e | Keyboard k and K | Y | Y | Y |
0f | Keyboard l and L | Y | Y | Y |
10 | Keyboard m and M | Y | Y | Y |
11 | Keyboard n and N | Y | Y | Y |
12 | Keyboard o and O | Y | Y | Y |
13 | Keyboard p and P | Y | Y | Y |
14 | Keyboard q and Q | Y | Y | Y |
15 | Keyboard r and R | Y | Y | Y |
16 | Keyboard s and S | Y | Y | Y |
17 | Keyboard t and T | Y | Y | Y |
18 | Keyboard u and U | Y | Y | Y |
19 | Keyboard v and V | Y | Y | Y |
1a | Keyboard w and W | Y | Y | Y |
1b | Keyboard x and X | Y | Y | Y |
1c | Keyboard y and Y | Y | Y | Y |
1d | Keyboard z and Z | Y | Y | Y |
1e | Keyboard 1 and ! | Y | Y | Y |
1f | Keyboard 2 and @ | Y | Y | Y |
20 | Keyboard 3 and # | Y | Y | Y |
21 | Keyboard 4 and $ | Y | Y | Y |
22 | Keyboard 5 and % | Y | Y | Y |
23 | Keyboard 6 and ^ | Y | Y | Y |
24 | Keyboard 7 and & | Y | Y | Y |
25 | Keyboard 8 and * | Y | Y | Y |
26 | Keyboard 9 and ( | Y | Y | Y |
27 | Keyboard 0 and ) | Y | Y | Y |
28 | Keyboard Return | Enter | Return | Return |
29 | Keyboard Escape | Y | Y | Y |
2a | Keyboard Delete (Backspace) | ← Backspace | ⌫ Delete | Y |
2b | Keyboard Tab | Y | Y | Y |
2c | Keyboard Spacebar | Y | Y | Y |
2d | Keyboard - and _ | Y | Y | Y |
2e | Keyboard = and + | Y | Y | Y |
2f | Keyboard [ and { | Y | Y | Y |
30 | Keyboard ] and } | Y | Y | Y |
31 | Keyboard \ and | | Y | Y | Y |
32 | Keyboard Int' # and ~ | Intended for key next to vertical Return key. Keyboard Backslash (0x31) is used instead.[Notes 2] | ||
33 | Keyboard ; and : | Y | Y | Y |
34 | Keyboard ‘ and “ | Y | Y | Y |
35 | Keyboard Grave Accent and Tilde | Y | Y | Y |
36 | Keyboard, and < | Y | Y | Y |
37 | Keyboard . and > | Y | Y | Y |
38 | Keyboard / and ? | Y | Y | Y |
39 | Keyboard Caps Lock | Y | Y | Y |
3a | Keyboard F1 | Y | Y | Y |
3b | Keyboard F2 | Y | Y | Y |
3c | Keyboard F3 | Y | Y | Y |
3d | Keyboard F4 | Y | Y | Y |
3e | Keyboard F5 | Y | Y | Y |
3f | Keyboard F6 | Y | Y | Y |
40 | Keyboard F7 | Y | Y | Y |
41 | Keyboard F8 | Y | Y | Y |
42 | Keyboard F9 | Y | Y | Y |
43 | Keyboard F10 | Y | Y | Y |
44 | Keyboard F11 | Y | Y | Y |
45 | Keyboard F12 | Y | Y | Y |
46 | Keyboard PrintScreen | Y | Y | Y |
47 | Keyboard Scroll Lock | Y | Y | Y |
48 | Keyboard Pause | Y | Y | Y |
49 | Keyboard Insert | Y | Y | Y |
4a | Keyboard Home | Y | Y | Y |
4b | Keyboard PageUp | Y | Y | Y |
4c | Keyboard Delete(forward) | Y | Y | Y |
4d | Keyboard End | Y | Y | Y |
4e | Keyboard PageDown | Y | Y | Y |
4f | Keyboard RightArrow | Y | Y | Y |
50 | Keyboard LeftArrow | Y | Y | Y |
51 | Keyboard DownArrow | Y | Y | Y |
52 | Keyboard UpArrow | Y | Y | Y |
53 | Keypad Num Lock and Clear | Num lock | Clear | Y |
54 | Keypad / | Y | Y | Y |
55 | Keypad * | Y | Y | Y |
56 | Keypad - | Y | Y | Y |
57 | Keypad + | Y | Y | Y |
58 | Keypad ENTER | Y | Enter | Y |
59 | Keypad 1 and End | Y | Y | Y |
5a | Keypad 2 and Down Arrow | Y | Y | Y |
5b | Keypad 3 and PageDn | Y | Y | Y |
5c | Keypad 4 and Left Arrow | Y | Y | Y |
5d | Keypad 5 | Y | Y | Y |
5e | Keypad 6 and Right Arrow | Y | Y | Y |
5f | Keypad 7 and Home | Y | Y | Y |
60 | Keypad 8 and Up Arrow | Y | Y | Y |
61 | Keypad 9 and PageUp | Y | Y | Y |
62 | Keypad 0 and Insert | Y | Y | Y |
63 | Keypad . and Delete | Y | Y | Y |
64 | Keyboard Int, \ and | (Between left Shift and Z on ISO layouts) | Y | Y | Y |
65 | Keyboard Application | Menu | Compose or Menu[Notes 3] | |
66 | Keyboard Power[Notes 4] | Y | Y | |
67 | Keypad = | [Notes 5] | Y | |
68 | Keyboard F13 | T | Y[Notes 6] | |
69 | Keyboard F14 | Y[Notes 6] | ||
6a | Keyboard F15 | Y[Notes 6] | ||
6b | Keyboard F16 | T[Notes 6] | ||
6c | Keyboard F17 | T[Notes 6] | ||
6d | Keyboard F18 | T[Notes 6] | ||
6e | Keyboard F19 | T[Notes 6] | ||
6f | Keyboard F20 | |||
70 | Keyboard F21 | |||
71 | Keyboard F22 | |||
72 | Keyboard F23 | |||
73 | Keyboard F24 | |||
74 | Keyboard Execute | Open[Notes 7] | ||
75 | Keyboard Help | Help[Notes 7] | ||
76 | Keyboard Menu | Props[Notes 7] | ||
77 | Keyboard Select | Front[Notes 7] | ||
78 | Keyboard Stop | Stop[Notes 7] | ||
79 | Keyboard Again | Again[Notes 7] | ||
7a | Keyboard Undo | Undo[Notes 7] | ||
7b | Keyboard Cut | Cut[Notes 7] | ||
7c | Keyboard Copy | Copy[Notes 7] | ||
7d | Keyboard Paste | Paste[Notes 7] | ||
7e | Keyboard Find | Find[Notes 7] | ||
7f | Keyboard Mute | Y[Notes 8] | ||
80 | Keyboard Volume Up | Y[Notes 8] | ||
81 | Keyboard Volume Down | Y[Notes 8] | ||
82 | Locking Caps Lock | |||
83 | Locking Num Lock | |||
84 | Locking Scroll Lock | |||
85 | Keypad ,[Notes 9] | Keypad . (Brazil) | ||
86 | Keypad Equals Sign Equals sign on AS/400 |
|||
87 | Keyboard INT1 Ro |
\/ろ (Japanese) / (Brazil) |
ろ (Japanese) | Y |
88 | Keyboard INT2 Kana |
カタカナ/ひらがな/ローマ字 (Japanese) | Y | Y |
89 | Keyboard INT3 Yen |
¥ (Japanese) | ¥ (Japanese) | Y |
8a | Keyboard INT4 Henkan (Conversion) |
変換/XFER (Japanese) | Y | Y |
8b | Keyboard INT5 Muhenkan (Non-conversion) |
無変換/NFER (Japanese) | Y | Y |
8c | Keyboard INT6 PC98 Keypad comma |
|||
8d | Keyboard INT7 PC98 Toggle single-byte/double-byte mode |
|||
8e | Keyboard INT8 | |||
8f | Keyboard INT9 | |||
90 | Keyboard LANG1 Hangul/English toggle (Korean) |
한/영 (Korean) | 한/영 (Korean) かな (Japanese) |
|
91 | Keyboard LANG2 Hanja conversion (Korean) |
한자 (Korean) | 한자 (Korean) 英数 (Japanese) |
|
92 | Keyboard LANG3 PC98 Katakana |
|||
93 | Keyboard LANG4 PC98 Hiragana |
|||
94 | Keyboard LANG5 PC98 "Kaku": Hankaku/Zenkaku ("Full-size"/"Half-size"/"Kanji") when not on Keyboard Tilde key (Japanese) |
|||
95 | Keyboard LANG6 PC98 Furigana (Hiragana as pronunciation-help above Kanji) |
|||
96 | Keyboard LANG7 | |||
97 | Keyboard LANG8 | |||
98 | Keyboard LANG9 | |||
99 | Keyboard Alternative Erase (Erase-Eaze) | |||
9a | Keyboard SysReq/Attention[Notes 10] | |||
9b | Keyboard Cancel | |||
9c | Keyboard Clear | [Notes 2] | ||
9d | Keyboard Prior | |||
9e | Keyboard Return | |||
9f | Keyboard Separator | |||
a0 | Keyboard Out | |||
a1 | Keyboard Oper | |||
a2 | Keyboard Clear/Again | |||
a3 | Keyboard ClSel/Props | |||
a4 | Keyboard ExSel | |||
a5 | Reserved | |||
a6 | Reserved | |||
a7 | Reserved | |||
a8 | Reserved | |||
a9 | Reserved | |||
aa | Reserved | |||
ab | Reserved | |||
ac | Reserved | |||
ad | Reserved | |||
ae | Reserved | |||
af | Reserved | |||
b0 | Keypad 00 | |||
b1 | Keypad 000 | |||
b2 | Thousands Separator | |||
b3 | Decimal Separator | |||
b4 | Currency Unit[Notes 11] | |||
b5 | Currency Sub-unit[Notes 11] | |||
b6 | Keypad ( | [Notes 5] | ||
b7 | Keypad ) | [Notes 5] | ||
b8 | Keypad { | |||
b9 | Keypad } | |||
ba | Keypad Tab | |||
bb | Keypad Backspace | |||
bc | Keypad A | |||
bd | Keypad B | |||
be | Keypad C | |||
bf | Keypad D | |||
c0 | Keypad E | |||
c1 | Keypad F | |||
c2 | Keypad XOR | |||
c3 | Keypad ^ | |||
c4 | Keypad % | |||
c5 | Keypad < | |||
c6 | Keypad > | |||
c7 | Keypad & | |||
c8 | Keypad && | |||
c9 | Keypad | | |||
ca | Keypad || | |||
cb | Keypad : | |||
cc | Keypad # | |||
cd | Keypad Space | |||
ce | Keypad @ | |||
cf | Keypad ! | |||
d0 | Keypad Memory Store | |||
d1 | Keypad Memory Recall | |||
d2 | Keypad Memory Clear | |||
d3 | Keypad Memory Add | |||
d4 | Keypad Memory Subtract | |||
d5 | Keypad Memory Multiply | |||
d6 | Keypad Memory Divide | |||
d7 | Keypad +/- | |||
d8 | Keypad Clear | |||
d9 | Keypad Clear Entry | |||
da | Keypad Binary | |||
db | Keypad Octal | |||
dc | Keypad Decimal | |||
dd | Keypad Hexadecimal | |||
de | Reserved | |||
df | Reserved | |||
e0 | Keyboard Left Control | Y | Y | Y |
e1 | Keyboard Left Shift | Y | Y | Y |
e2 | Keyboard Left Alt | Y | Y | Y |
e3 | Keyboard Left GUI | Windows | Command | Meta[Notes 12] |
e4 | Keyboard Right Control | Y | Y | Y |
e5 | Keyboard Right Shift | Y | Y | Y |
e6 | Keyboard Right Alt | Y | Y | Y |
e7 | Keyboard Right GUI | Windows | Command | Meta[Notes 12] |
e8 to FFFF | Reserved |
Notes
- ↑ 1.0 1.1 1.2 ErrorRollOver, POSTFail and ErrorUndefined are status codes, not physical keys.
- ↑ 2.0 2.1 Some versions of Linux are known to exhibit bugs if a report contains 'Keyboard Int # and ~' (0x32) or 'Keyboard Clear'(0x9a)
- ↑ The 'Keyboard Application' key is configurable under Unix/Linux, with different defaults in different desktop environments. Sun Type 6 and Sun Type 7's Compose key sends this code.
- ↑ According to the spec, 'Keyboard Power' is only a status code, not a physical key.
- ↑ 5.0 5.1 5.2 Some of Microsoft's own keyboards send Keypad =, Keypad ( and Keypad ) on a separate "Generic HID" interface, not on the main "Keyboard" interface. Those are not supported by MS Windows itself but require a special driver.
- ↑ 6.0 6.1 6.2 6.3 6.4 6.5 6.6 Full-size USB keyboards from Apple have additional function keys that the more compact keyboards lack. The Apple Pro Keyboard introduced F13..F15. The full-sized Apple Aluminium Keyboard introduced F16 to F19 above the numeric keypad. Those are seldom used by Mac apps, and can be mapped to specific functions in MacOS. F14 and F15 come mapped to brightness controls in some versions of MacOS, but that can be changed.
- ↑ 7.00 7.01 7.02 7.03 7.04 7.05 7.06 7.07 7.08 7.09 7.10 The named function keys on Sun Type 6 and Sun Type 7 keyboards. Mapping from Kenti.net.
- ↑ 8.0 8.1 8.2 Media keys in top/right corner on Sun Type 6 and Sun Type 7
- ↑ Brazilian layout uses this key for thousands-separator. The 'Keypad +' key and this key together occupy the same space as a vertical 'Keypad +' key does on most other PC keyboards.
- ↑ Usage of keys is not modified by the state of the Control, Alt, Shift or Num Lock keys
- ↑ 11.0 11.1 Based on OS current language settings, e.g £ for GB $ for US, (period) for US/GB decimal (comma) for Int
- ↑ 12.0 12.1 Meta key on Sun Type 6 and Sun Type 7. Defaults to Super in some desktop environments.
Media keys
There are more codes in the USB standard that those below, but not all are supported by major operating systems and apps. [2] [3] [4] [5].
Values are in hexadecimal.
Function | USB | PS/2 (set 2) | OS support | ||||||
---|---|---|---|---|---|---|---|---|---|
System | Page | Code | Type | Make | Break | Windows | Mac | X | Sun |
Power | 01 | 81 | One-shot | E0 37 | E0 F0 37 | Windows 95 | X | ||
07 | 66 | One-shot | Mac | X | Sun | ||||
Sleep | 01 | 82 | One-shot | E0 3F | E0 F0 3F | Windows 95 | |||
Wake | 01 | 83 | One-shot | E0 5E | E0 F0 5E | Windows 95 | |||
Media | Page | Code | Type | Make | Break | Windows | Mac | X | Sun |
Next Track | 0C | B5 | One-shot | E0 4D | E0 F0 4D | Windows | Mac | X | |
Previous Track | 0C | B6 | One-shot | E0 15 | E0 F0 15 | Windows | Mac | X | |
Stop | 0C | B7 | One-shot | E0 3B | E0 F0 3B | Windows | Mac | X | |
Eject | 0C | B8 | One-shot | Mac | |||||
Play / Pause | 0C | CD | One-shot | E0 34 | E0 F0 34 | Windows | Mac | X | |
Volume (knob) | 0C | E0 | Linear | Windows 98 | |||||
Mute | 0C | E2 | On/off | E0 23 | E0 F0 23 | Windows 98 | Mac | X | |
07 | 7F | One-shot | Sun | ||||||
Bass (knob) | 0C | E3 | Linear | Windows 2000 | |||||
Treble (knob) | 0C | E4 | Linear | Windows 2000 | |||||
Bass Boost | 0C | E5 | On/off | Windows 98 | |||||
Loudness | 0C | E7 | On/off | Windows 2000 | |||||
Volume Up | 0C | E9 | Re-trigger | E0 32 | E0 F0 32 | Windows 98 | Mac | X | |
07 | 80 | One-shot | Sun | ||||||
Volume Down | 0C | EA | Re-trigger | E0 21 | E0 F0 21 | Windows 98 | Mac | X | |
07 | 81 | One-shot | Sun | ||||||
Bass Up | 0C | 0152 | Re-trigger | Windows 2000 | |||||
Bass Down | 0C | 0153 | Re-trigger | Windows 2000 | |||||
Treble Up | 0C | 0154 | Re-trigger | Windows 2000 | |||||
Treble Down | 0C | 0155 | Re-trigger | Windows 2000 | |||||
Launch application | Page | Code | Type | Make | Break | Windows | Mac | X | Sun |
Media Player | 0C | 0183 | Selector | E0 50 | E0 F0 50 | Windows | |||
0C | 018A | Selector | E0 48 | E0 F0 48 | Windows | ||||
Calculator | 0C | 0192 | Selector | E0 2B | E0 F0 2B | Windows | |||
My Computer | 0C | 0194 | Selector | E0 40 | E0 F0 40 | Windows | |||
Web browser | Page | Code | Type | Make | Break | Windows | Mac | X | Sun |
Search | 0C | 0221 | Selector | E0 10 | E0 F0 10 | Windows | |||
Browser/Home | 0C | 0223 | Selector | E0 3A | E0 F0 3A | Windows | |||
Back | 0C | 0224 | Selector | E0 38 | E0 F0 38 | Windows | |||
Forward | 0C | 0225 | Selector | E0 30 | E0 F0 30 | Windows | |||
Stop | 0C | 0226 | Selector | E0 28 | E0 F0 28 | Windows | |||
Refresh | 0C | 0227 | Selector | E0 20 | E0 F0 20 | Windows | |||
Bookmarks | 0C | 022A | Selector | E0 18 | E0 F0 18 | Windows |
References
- ↑ Ed Nisley: How the PC Keyboard Got Its Bits. Circuit Cellar, issue #59 June 1995. Page 46.
- ↑ Universal Serial Bus (USB): HID Usage Tables,10/28/2004,Version 1.12
- ↑ Windows Platform Design Notes: Keyboard Scan Code Specification, Revision 1.3a; revised March 2000. Retrieved from Archive: Key Support, Keyboard Scan Codes, and Windows on 2013-09-19
- ↑ USB HID to PS/2 Scan Code Translation Table. Retrieved from Archive: Key Support, Keyboard Scan Codes, and Windows on 2013-09-19
- ↑ Sun USB media key mappings, extracted from looking at the source code of type5usb.