DRAFT |
SDL_Scancode and SDL_Keycode
The SDL physical and virtual key representations.
SDL_ScanCode values are used to represent the physical location of a keyboard key on the keyboard. Values of this type are used to represent keyboard keys in the key.keysym.scancode field of the SDL_Event structure, among other places. The values in the SDL_ScanCode enumeration are based on the USB usage page standard (http://www.usb.org/developers/devclass_docs/Hut1_12.pdf).
SDLKey values (also known as keycodes or keysyms) are mapped to the current layout of the keyboard and correlate to an SDL_scancode. Values of this type are used to represent key symbols in the key.keysym.sym field of the SDL_Event structure, among other places. The values in the SDLKey enumeration are based on Unicode values representing the unmodified character that would be generated by pressing the key, or the scancode value with the high bit set (bitwise ANDed with 0x8000000) for those keys that do not generate characters.
The main difference between these two values comes in to play in situations where the operating system is mapping the physical keyboard keys to different virtual letters. For instance, when a standard QWERTY keyboard is mapped to a German QWERTZ layout, the "Y" key will generate events with a scancode of SDL_SCANCODE_Y, but a keycode of SDLK_z. Which to use is left to the application: scancodes are suited in situations where controls are layout-dependent (eg. the "WASD" keys as left-handed arrow keys), wheras keycodes are better suited to situations where controls are character-dependent (eg. the "I" key for Inventory).
Scancode constants use the symbol name prefixed with SDL_SCANCODE_. Keycode constants use the symbol name (lowercased for letters) prefixed with SDLK_.
The name of a key can be obtained using SDLGetKeyName with the keycode or SDLGetScancodeName with the scancode.
Symbol |
Scancode |
Keycode |
Name |
UNKNOWN |
0 |
0 (0x00, '\0') |
(none) |
These values are mapped from usage page 0x07 (USB keyboard page) |
|||
A |
4 |
97 (0x61, 'a') |
A |
B |
5 |
98 (0x62, 'b') |
B |
C |
6 |
99 (0x63, 'c') |
C |
D |
7 |
100 (0x64, 'd') |
D |
E |
8 |
101 (0x65, 'e') |
E |
F |
9 |
102 (0x66, 'f') |
F |
G |
10 |
103 (0x67, 'g') |
G |
H |
11 |
104 (0x68, 'h') |
H |
I |
12 |
105 (0x69, 'i') |
I |
J |
13 |
106 (0x6A, 'j') |
J |
K |
14 |
107 (0x6B, 'k') |
K |
L |
15 |
108 (0x6C, 'l') |
L |
M |
16 |
109 (0x6D, 'm') |
M |
N |
17 |
110 (0x6E, 'n') |
N |
O |
18 |
111 (0x6F, 'o') |
O |
P |
19 |
112 (0x70, 'p') |
P |
Q |
20 |
113 (0x71, 'q') |
Q |
R |
21 |
114 (0x72, 'r') |
R |
S |
22 |
115 (0x73, 's') |
S |
T |
23 |
116 (0x74, 't') |
T |
U |
24 |
117 (0x75, 'u') |
U |
V |
25 |
118 (0x76, 'v') |
V |
W |
26 |
119 (0x77, 'w') |
W |
X |
27 |
120 (0x78, 'x') |
X |
Y |
28 |
121 (0x79, 'y') |
Y |
Z |
29 |
122 (0x7A, 'z') |
Z |
1 |
30 |
49 (0x31, '1') |
1 |
2 |
31 |
50 (0x32, '2') |
2 |
3 |
32 |
51 (0x33, '3') |
3 |
4 |
33 |
52 (0x34, '4') |
4 |
5 |
34 |
53 (0x35, '5') |
5 |
6 |
35 |
54 (0x36, '6') |
6 |
7 |
36 |
55 (0x37, '7') |
7 |
8 |
37 |
56 (0x38, '8') |
8 |
9 |
38 |
57 (0x39, '9') |
9 |
0 |
39 |
48 (0x30, '0') |
0 |
RETURN |
40 |
13 (0x0D, '\r') |
Return; the Enter key (main keyboard) |
ESCAPE |
41 |
27 (0x1B, '\033') |
Escape; the Esc key |
BACKSPACE |
42 |
8 (0x08, '\b') |
Backspace |
TAB |
43 |
9 (0x09, '\t') |
Tab; the Tab key |
SPACE |
44 |
32 (0x20, ' ') |
Space; the Space Bar key(s) |
MINUS |
45 |
45 (0x2D, '-') |
- |
EQUALS |
46 |
61 (0x3D, '=') |
= |
LEFTBRACKET |
47 |
91 (0x5B, '[') |
[ |
RIGHTBRACKET |
48 |
93 (0x5D, ']') |
] |
BACKSLASH |
49 |
92 (0x5C, '\\') |
\; Located at the lower left of the return key on ISO keyboards and at the right end of the QWERTY row on ANSI keyboards. Produces REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US layout, REVERSE SOLIDUS and VERTICAL LINE in a UK Mac layout, NUMBER SIGN and TILDE in a UK Windows layout, DOLLAR SIGN and POUND SIGN in a Swiss German layout, NUMBER SIGN and APOSTROPHE in a German layout, GRAVE ACCENT and POUND SIGN in a French Mac layout, and ASTERISK and MICRO SIGN in a French Windows layout. |
NONUSHASH |
50 |
(none) |
#; ISO USB keyboards actually use this code instead of 49 for the same key, but all OSes I've seen treat the two codes identically. So, as an implementor, unless your keyboard generates both of those codes and your OS treats them differently, you should generate SDL_SCANCODE_BACKSLASH instead of this code. As a user, you should not rely on this code because SDL will never generate it with most (all?) keyboards. |
SEMICOLON |
51 |
59 (0x3B, ';') |
; |
APOSTROPHE |
52 |
39 (0x27, '\'') |
' |
GRAVE |
53 |
96 (0x60, '`') |
`; Located in the top left corner (on both ANSI and ISO keyboards). Produces GRAVE ACCENT and TILDE in a US Windows layout and in US and UK Mac layouts on ANSI keyboards, GRAVE ACCENT and NOT SIGN in a UK Windows layout, SECTION SIGN and PLUS-MINUS SIGN in US and UK Mac layouts on ISO keyboards, SECTION SIGN and DEGREE SIGN in a Swiss German layout (Mac: only on ISO keyboards), CIRCUMFLEX ACCENT and DEGREE SIGN in a German layout (Mac: only on ISO keyboards), SUPERSCRIPT TWO and TILDE in a French Windows layout, COMMERCIAL AT and NUMBER SIGN in a French Mac layout on ISO keyboards, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French Mac layout on ANSI keyboards. |
COMMA |
54 |
44 (0x2C, ',') |
, |
PERIOD |
55 |
46 (0x2E, '.') |
. |
SLASH |
56 |
47 (0x2F, '/') |
/ |
CAPSLOCK |
57 |
0x80000039 |
|
F1 |
58 |
0x8000003A |
F1 |
F2 |
59 |
0x8000003B |
F2 |
F3 |
60 |
0x8000003C |
F3 |
F4 |
61 |
0x8000003D |
F4 |
F5 |
62 |
0x8000003E |
F5 |
F6 |
63 |
0x8000003F |
F6 |
F7 |
64 |
0x80000040 |
F7 |
F8 |
65 |
0x80000041 |
F8 |
F9 |
66 |
0x80000042 |
F9 |
F10 |
67 |
0x80000043 |
F10 |
F11 |
68 |
0x80000044 |
F11 |
F12 |
69 |
0x80000045 |
F12 |
PRINTSCREEN |
70 |
0x80000046 |
|
SCROLLLOCK |
71 |
0x80000047 |
|
PAUSE |
72 |
0x80000048 |
Pause; the Pause / Break key |
INSERT |
73 |
0x80000049 |
Insert; insert on PC, help on some Mac keyboards (but does send code 73, not 117) |
HOME |
74 |
0x8000004A |
Home |
PAGEUP |
75 |
0x8000004B |
|
DELETE |
76 |
177 (0xB1, '\177') |
Delete |
END |
77 |
0x8000004D |
End |
PAGEDOWN |
78 |
0x8000004E |
|
RIGHT |
79 |
0x8000004F |
Right; the Right arrow key (navigation keypad) |
LEFT |
80 |
0x80000050 |
Left; the Left arrow key (navigation keypad) |
DOWN |
81 |
0x80000051 |
Down; the Down arrow key (navigation keypad) |
UP |
82 |
0x80000052 |
Up; the Up arrow key (navigation keypad) |
NUMLOCKCLEAR |
83 |
0x80000053 |
Numlock; the Num Lock key (PC) / the Clear key (Mac) |
KP_DIVIDE |
84 |
0x80000054 |
Keypad /; the / key (numeric keypad) |
KP_MULTIPLY |
85 |
0x80000055 |
Keypad *; the * key (numeric keypad) |
KP_MINUS |
86 |
0x80000056 |
Keypad -; the - key (numeric keypad) |
KP_PLUS |
87 |
0x80000057 |
Keypad +; the + key (numeric keypad) |
KP_ENTER |
88 |
0x80000058 |
Keypad Enter; the Enter key (numeric keypad) |
KP_1 |
89 |
0x80000059 |
Keypad 1; the 1 key (numeric keypad) |
KP_2 |
90 |
0x8000005A |
Keypad 2; the 2 key (numeric keypad) |
KP_3 |
91 |
0x8000005B |
Keypad 3; the 3 key (numeric keypad) |
KP_4 |
92 |
0x8000005C |
Keypad 4; the 4 key (numeric keypad) |
KP_5 |
93 |
0x8000005D |
Keypad 5; the 5 key (numeric keypad) |
KP_6 |
94 |
0x8000005E |
Keypad 6; the 6 key (numeric keypad) |
KP_7 |
95 |
0x8000005F |
Keypad 7; the 7 key (numeric keypad) |
KP_8 |
96 |
0x80000060 |
Keypad 8; the 8 key (numeric keypad) |
KP_9 |
97 |
0x80000061 |
Keypad 9; the 9 key (numeric keypad) |
KP_0 |
98 |
0x80000062 |
Keypad 0; the 0 key (numeric keypad) |
KP_PERIOD |
99 |
0x80000063 |
Keypad .; the . key (numeric keypad) |
NONUSBACKSLASH |
100 |
(none) |
(none); This is the additional key that ISO keyboards have over ANSI ones, located between left shift and Y. Produces GRAVE ACCENT and TILDE in a US or UK Mac layout, REVERSE SOLIDUS (backslash) and VERTICAL LINE in a US or UK Windows layout, and LESS-THAN SIGN and GREATER-THAN SIGN in a Swiss German, German, or French layout. |
APPLICATION |
101 |
0x80000065 |
Application; the Application / Compose / Context Menu (Windows) key |
POWER |
102 |
0x80000066 |
Power; The USB document says this is a status flag, not a physical key - but some Mac keyboards do have a power key. |
KP_EQUALS |
103 |
0x80000067 |
Keypad =; the = key (numeric keypad) |
F13 |
104 |
0x80000068 |
F13 |
F14 |
105 |
0x80000069 |
F14 |
F15 |
106 |
0x8000006A |
F15 |
F16 |
107 |
0x8000006B |
F16 |
F17 |
108 |
0x8000006C |
F17 |
F18 |
109 |
0x8000006D |
F18 |
F19 |
110 |
0x8000006E |
F19 |
F20 |
111 |
0x8000006F |
F20 |
F21 |
112 |
0x80000070 |
F21 |
F22 |
113 |
0x80000071 |
F22 |
F23 |
114 |
0x80000072 |
F23 |
F24 |
115 |
0x80000073 |
F24 |
EXECUTE |
116 |
0x80000074 |
Execute |
HELP |
117 |
0x80000075 |
Help |
MENU |
118 |
0x80000076 |
Menu |
SELECT |
119 |
0x80000077 |
Select |
STOP |
120 |
0x80000078 |
Stop |
AGAIN |
121 |
0x80000079 |
Again; the Again key (Redo) |
UNDO |
122 |
0x8000007A |
Undo |
CUT |
123 |
0x8000007B |
Cut |
COPY |
124 |
0x8000007C |
Copy |
PASTE |
125 |
0x8000007D |
Paste |
FIND |
126 |
0x8000007E |
Find |
MUTE |
127 |
0x8000007F |
Mute |
VOLUMEUP |
128 |
0x80000080 |
|
VOLUMEDOWN |
129 |
0x80000081 |
|
The keys below are commented out in SDL_scancode.h |
|||
LOCKINGCAPSLOCK |
130 |
(none) |
(none) |
LOCKINGNUMLOCK |
131 |
(none) |
(none) |
LOCKINGSCROLLLOCK |
132 |
(none) |
(none) |
The keys above are commented out in SDL_scancode.h |
|||
KP_COMMA |
133 |
0x80000085 |
Keypad ,; the Comma key (numeric keypad) |
KP_EQUALSAS400 |
134 |
0x80000086 |
Keypad = (AS400); the Equals AS400 key (numeric keypad) |
INTERNATIONAL1 |
135 |
(none) |
(none); used on Asian keyboards, see footnotes in USB doc |
INTERNATIONAL2 |
136 |
(none) |
(none) |
INTERNATIONAL3 |
137 |
(none) |
(none); Yen |
INTERNATIONAL4 |
138 |
(none) |
(none) |
INTERNATIONAL5 |
139 |
(none) |
(none) |
INTERNATIONAL6 |
140 |
(none) |
(none) |
INTERNATIONAL7 |
141 |
(none) |
(none) |
INTERNATIONAL8 |
142 |
(none) |
(none) |
INTERNATIONAL9 |
143 |
(none) |
(none) |
LANG1 |
144 |
(none) |
(none); Hangul/English toggle |
LANG2 |
145 |
(none) |
(none); Hanja conversion |
LANG3 |
146 |
(none) |
(none); Katakana |
LANG4 |
147 |
(none) |
(none); Hiragana |
LANG5 |
148 |
(none) |
(none); Zenkaku/Hankaku |
LANG6 |
149 |
(none) |
(none); reserved |
LANG7 |
150 |
(none) |
(none); reserved |
LANG8 |
151 |
(none) |
(none); reserved |
LANG9 |
152 |
(none) |
(none); reserved |
ALTERASE |
153 |
0x80000099 |
AltErase; Erase-Eaze |
SYSREQ |
154 |
0x8000009A |
SysReq; the SysReq key |
CANCEL |
155 |
0x8000009B |
Cancel |
CLEAR |
156 |
0x8000009C |
Clear |
PRIOR |
157 |
0x8000009D |
Prior |
RETURN2 |
158 |
0x8000009E |
Return |
SEPARATOR |
159 |
0x8000009F |
Separator |
OUT |
160 |
0x800000A0 |
Out |
OPER |
161 |
0x800000A1 |
Oper |
CLEARAGAIN |
162 |
0x800000A2 |
Clear / Again |
CRSEL |
163 |
0x800000A3 |
|
EXSEL |
164 |
0x800000A4 |
|
KP_00 |
176 |
0x800000B0 |
Keypad 00; the 00 key (numeric keypad) |
KP_000 |
177 |
0x800000B1 |
Keypad 000; the 000 key (numeric keypad) |
THOUSANDSSEPARATOR |
178 |
0x800000B2 |
ThousandsSeparator; the Thousands Separator key |
DECIMALSEPARATOR |
179 |
0x800000B3 |
DecimalSeparator; the Decimal Separator key |
CURRENCYUNIT |
180 |
0x800000B4 |
CurrencyUnit; the Currency Unit key |
CURRENCYSUBUNIT |
181 |
0x800000B5 |
CurrencySubUnit; the Currency Subunit key |
KP_LEFTPAREN |
182 |
0x800000B6 |
Keypad (; the Left Parenthesis key (numeric keypad) |
KP_RIGHTPAREN |
183 |
0x800000B7 |
Keypad ); the Right Parenthesis key (numeric keypad) |
KP_LEFTBRACE |
184 |
0x800000B8 |
Keypad {; the Left Brace key (numeric keypad) |
KP_RIGHTBRACE |
185 |
0x800000B9 |
Keypad }; the Right Brace key (numeric keypad) |
KP_TAB |
186 |
0x800000BA |
Keypad Tab; the Tab key (numeric keypad) |
KP_BACKSPACE |
187 |
0x800000BB |
Keypad Backspace; the Backspace key (numeric keypad) |
KP_A |
188 |
0x800000BC |
Keypad A; the A key (numeric keypad) |
KP_B |
189 |
0x800000BD |
Keypad B; the B key (numeric keypad) |
KP_C |
190 |
0x800000BE |
Keypad C; the C key (numeric keypad) |
KP_D |
191 |
0x800000BF |
Keypad D; the D key (numeric keypad) |
KP_E |
192 |
0x800000C0 |
Keypad E; the E key (numeric keypad) |
KP_F |
193 |
0x800000C1 |
Keypad F; the F key (numeric keypad) |
KP_XOR |
194 |
0x800000C2 |
Keypad XOR; the XOR key (numeric keypad) |
KP_POWER |
195 |
0x800000C3 |
Keypad ^; the Power key (numeric keypad) |
KP_PERCENT |
196 |
0x800000C4 |
Keypad %; the Percent key (numeric keypad) |
KP_LESS |
197 |
0x800000C5 |
Keypad <; the Less key (numeric keypad) |
KP_GREATER |
198 |
0x800000C6 |
Keypad >; the Greater key (numeric keypad) |
KP_AMPERSAND |
199 |
0x800000C7 |
Keypad &; the & key (numeric keypad) |
KP_DBLAMPERSAND |
200 |
0x800000C8 |
Keypad &&; the && key (numeric keypad) |
KP_VERTICALBAR |
201 |
0x800000C9 |
Keypad |; the | key (numeric keypad) |
KP_DBLVERTICALBAR |
202 |
0x800000CA |
Keypad ||; the || key (numeric keypad) |
KP_COLON |
203 |
0x800000CB |
Keypad :; the : key (numeric keypad) |
KP_HASH |
204 |
0x800000CC |
Keypad #; the # key (numeric keypad) |
KP_SPACE |
205 |
0x800000CD |
Keypad Space; the Space key (numeric keypad) |
KP_AT |
206 |
0x800000CE |
Keypad @; the @ key (numeric keypad) |
KP_EXCLAM |
207 |
0x800000CF |
Keypad !; the ! key (numeric keypad) |
KP_MEMSTORE |
208 |
0x800000D0 |
Keypad MemStore; the Mem Store key (numeric keypad) |
KP_MEMRECALL |
209 |
0x800000D1 |
Keypad MemRecall; the Mem Recall key (numeric keypad) |
KP_MEMCLEAR |
210 |
0x800000D2 |
Keypad MemClear; the Mem Clear key (numeric keypad) |
KP_MEMADD |
211 |
0x800000D3 |
Keypad MemAdd; the Mem Add key (numeric keypad) |
KP_MEMSUBTRACT |
212 |
0x800000D4 |
Keypad MemSubtract; the Mem Subtract key (numeric keypad) |
KP_MEMMULTIPLY |
213 |
0x800000D5 |
Keypad MemMultiply; the Mem Multiply key (numeric keypad) |
KP_MEMDIVIDE |
214 |
0x800000D6 |
Keypad MemDivide; the Mem Divide key (numeric keypad) |
KP_PLUSMINUS |
215 |
0x800000D7 |
Keypad +/-; the +/- key (numeric keypad) |
KP_CLEAR |
216 |
0x800000D8 |
Keypad Clear; the Clear key (numeric keypad) |
KP_CLEARENTRY |
217 |
0x800000D9 |
Keypad ClearEntry; the Clear Entry key (numeric keypad) |
KP_BINARY |
218 |
0x800000DA |
Keypad Binary; the Binary key (numeric keypad) |
KP_OCTAL |
219 |
0x800000DB |
Keypad Octal; the Octal key (numeric keypad) |
KP_DECIMAL |
220 |
0x800000DC |
Keypad Decimal; the Decimal key (numeric keypad) |
KP_HEXADECIMAL |
221 |
0x800000DD |
Keypad Hexadecimal; the Hexadecimal key (numeric keypad) |
LCTRL |
224 |
0x800000E0 |
Left Ctrl |
LSHIFT |
225 |
0x800000E1 |
Left Shift |
LALT |
226 |
0x800000E2 |
Left Alt; alt, option |
LGUI |
227 |
0x800000E3 |
Left GUI; windows, command (apple), meta |
RCTRL |
228 |
0x800000E4 |
Right Ctrl |
RSHIFT |
229 |
0x800000E5 |
Right Shift |
RALT |
230 |
0x800000E6 |
Right Alt; alt gr, option |
RGUI |
231 |
0x800000E7 |
Right GUI; windows, command (apple), meta |
MODE |
257 |
0x80000101 |
ModeSwitch; I'm not sure if this is really not covered by any of the above, but since there's a special KMOD_MODE for it I'm adding it here |
These values are mapped from usage page 0x0C (USB consumer page) |
|||
AUDIONEXT |
258 |
0x80000102 |
AudioNext; the Next Track media key |
AUDIOPREV |
259 |
0x80000103 |
AudioPrev; the Previous Track media key |
AUDIOSTOP |
260 |
0x80000104 |
AudioStop; the Stop media keykey |
AUDIOPLAY |
261 |
0x80000105 |
AudioPlay; the Play media keykey |
AUDIOMUTE |
262 |
0x80000106 |
AudioMute; the Mute volume key |
MEDIASELECT |
263 |
0x80000107 |
MediaSelect; the Media Select key |
WWW |
264 |
0x80000108 |
WWW; the WWW/World Wide Web key |
265 |
0x80000109 |
Mail; the Mail/eMail key |
|
CALCULATOR |
266 |
0x8000010A |
Calculator; the Calculator key |
COMPUTER |
267 |
0x8000010B |
Computer; the My Computer key |
AC_SEARCH |
268 |
0x8000010C |
AC Search; the Search key (application control keypad) |
AC_HOME |
269 |
0x8000010D |
AC Home; the Home key (application control keypad) |
AC_BACK |
270 |
0x8000010E |
AC Back; the Back key (application control keypad) |
AC_FORWARD |
271 |
0x8000010F |
AC Forward; the Forward key (application control keypad) |
AC_STOP |
272 |
0x80000110 |
AC Stop; the Stop key (application control keypad) |
AC_REFRESH |
273 |
0x80000111 |
AC Refresh; the Refresh key (application control keypad) |
AC_BOOKMARKS |
274 |
0x80000112 |
AC Bookmarks; the Bookmarks key (application control keypad) |
These are values that Christian Walther added (for mac keyboard?) |
|||
BRIGHTNESSDOWN |
275 |
0x80000113 |
BrightnessDown; the Brightness Down key |
BRIGHTNESSUP |
276 |
0x80000114 |
BrightnessUp; the Brightness Up key |
DISPLAYSWITCH |
277 |
0x80000115 |
DisplaySwitch; display mirroring/dual display switch, video mode switch |
KBDILLUMTOGGLE |
278 |
0x80000116 |
KBDIllumToggle; the Keyboard Illumination Toggle key |
KBDILLUMDOWN |
279 |
0x80000117 |
KBDIllumDown; the Keyboard Illumination Down key |
KBDILLUMUP |
280 |
0x80000118 |
KBDIllumUp; the Keyboard Illumination Up key |
EJECT |
281 |
0x80000119 |
Eject; the Eject key |
SLEEP |
282 |
0x8000011A |
Sleep; the Sleep key |
Code Examples
//checks if a key is being remapped and prints what the remapping is
if(event->key.keysym.scancode != SDL_GetScancodeFromKey(event->key.keysym.sym))
printf("Physical %s key acting as %s key",
SDL_GetScancodeName(event->key.keysym.scancode),
SDL_GetKeyName(event->key.keysym.sym));
Related Enumerations
Related Functions
(no category)