From Deskthority wiki
Jump to: navigation, search

This article is a stub. You can help Deskthority by expanding it.

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

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.


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 Y Y Y
02 Keyboard POSTFail Y Y Y
03 Keyboard ErrorUndefined 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.
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 1]
66 Keyboard Power[Notes 2] Y Y
67 Keypad = T Y
68 Keyboard F13 T Y
69 Keyboard F14 Y
6a Keyboard F15 Y
6b Keyboard F16
6c Keyboard F17
6d Keyboard F18
6e Keyboard F19
6f Keyboard F20
70 Keyboard F21
71 Keyboard F22
72 Keyboard F23
73 Keyboard F24
74 Keyboard Execute Open[Notes 3]
75 Keyboard Help Help[Notes 3]
76 Keyboard Menu Props[Notes 3]
77 Keyboard Select Front[Notes 3]
78 Keyboard Stop Stop[Notes 3]
79 Keyboard Again Again[Notes 3]
7a Keyboard Undo Undo[Notes 3]
7b Keyboard Cut Cut[Notes 3]
7c Keyboard Copy Copy[Notes 3]
7d Keyboard Paste Paste[Notes 3]
7e Keyboard Find Find[Notes 3]
7f Keyboard Mute Y[Notes 4]
80 Keyboard Volume Up Y[Notes 4]
81 Keyboard Volume Down Y[Notes 4]
82 Locking Caps Lock
83 Locking Num Lock
85 Keypad ,[Notes 5] Y
86 Keypad Equals Sign[Notes 6]
87 Keyboard INT1
Ro (Japanese)
88 Keyboard INT2
Kana (Japanese)
89 Keyboard INT3
¥ (Japanese)
8a Keyboard INT4
Henkan (Japanese)
8b Keyboard INT5
Muhenkan (Japanese)
8c Keyboard INT6
8d Keyboard INT7
8e Keyboard INT8
8f Keyboard INT9
90 Keyboard LANG1
Hangul / English toggle (Korean)
91 Keyboard LANG2
Convert to "Hanja" characters (Korean)
92 Keyboard LANG3
Katakana (Japanese)
93 Keyboard LANG4
Hiragana (Japanese)
94 Keyboard LANG5
"Kaku": Hankaku/Zenkaku ("Full-size"/"Half-size"/"Kanji") when not on Keyboard Tilde key (Japanese)
95 Keyboard LANG6
96 Keyboard LANG7
97 Keyboard LANG8
98 Keyboard LANG9
99 Keyboard Alternative Erase (Erase-Eaze)
9a Keyboard SysReq/Attention[Notes 7]
9b Keyboard Cancel
9c Keyboard Clear
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 8]
b5 Currency Sub-unit[Notes 8]
b6 Keypad (
b7 Keypad )
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 9]
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 9]
e8 to FFFF Reserved


  1. The key is configurable under Unix/Linux, with different defaults in different desktop environments.
  2. Mac external Keyboard power , may not apply built in keyboard on laptops (rMBP etc).
  3. 3.00 3.01 3.02 3.03 3.04 3.05 3.06 3.07 3.08 3.09 3.10 The named function keys on Sun Type 6 and Sun Type 7 keyboards. Mapping from
  4. 4.0 4.1 4.2 Media keys in top/right corner on Sun Type 6 and Sun Type 7
  5. Your OS may treat this as Keypad . depends on your keyboard layout or language settings
  6. Unsure how this differs from Scancode 67.
  7. Usage of keys is not modified by the state of the Control, Alt, Shift or Num Lock keys
  8. 8.0 8.1 Based on OS current language settings, e.g £ for GB $ for US, (period) for US/GB decimal (comma) for Int
  9. 9.0 9.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 B5 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
Email 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


  1. Ed Nisley: How the PC Keyboard Got Its Bits. Circuit Cellar, issue #59 June 1995. Page 46.
  2. Universal Serial Bus (USB): HID Usage Tables,10/28/2004,Version 1.12
  3. 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
  4. USB HID to PS/2 Scan Code Translation Table. Retrieved from Archive: Key Support, Keyboard Scan Codes, and Windows on 2013-09-19
  5. Sun USB media key mappings, extracted from looking at the source code of type5usb.