-
Notifications
You must be signed in to change notification settings - Fork 2
/
usb_keys.h
387 lines (340 loc) · 11.1 KB
/
usb_keys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/**
* usb_keys.h: USB keycodes
*
* Copied from various USB specifications and random websites. These seem to
* work for my use cases, but no guarantees that either the naming or the
* values are accurate.
*
* Composed by Kimmo Kulovesi, https://arkku.dev/
* Provided with absolutely no warranty, use at your own risk only.
* Use and distribute freely, mark modified copies as such.
*/
#ifndef KK_USB_KEYS_H
#define KK_USB_KEYS_H
enum keycode_usb {
// MARK: - Error codes
USB_KEY_ROLLOVER = 0x01,
USB_KEY_POST_FAIL = 0x02,
USB_KEY_UNDEFINED_ERROR = 0x03,
// MARK: - 7-bit keycodes
USB_KEY_A = 0x04,
USB_KEY_B = 0x05,
USB_KEY_C = 0x06,
USB_KEY_D = 0x07,
USB_KEY_E = 0x08,
USB_KEY_F = 0x09,
USB_KEY_G = 0x0A,
USB_KEY_H = 0x0B,
USB_KEY_I = 0x0C,
USB_KEY_J = 0x0D,
USB_KEY_K = 0x0E,
USB_KEY_L = 0x0F,
USB_KEY_M = 0x10,
USB_KEY_N = 0x11,
USB_KEY_O = 0x12,
USB_KEY_P = 0x13,
USB_KEY_Q = 0x14,
USB_KEY_R = 0x15,
USB_KEY_S = 0x16,
USB_KEY_T = 0x17,
USB_KEY_U = 0x18,
USB_KEY_V = 0x19,
USB_KEY_W = 0x1A,
USB_KEY_X = 0x1B,
USB_KEY_Y = 0x1C,
USB_KEY_Z = 0x1D,
USB_KEY_1 = 0x1E,
USB_KEY_2 = 0x1F,
USB_KEY_3 = 0x20,
USB_KEY_4 = 0x21,
USB_KEY_5 = 0x22,
USB_KEY_6 = 0x23,
USB_KEY_7 = 0x24,
USB_KEY_8 = 0x25,
USB_KEY_9 = 0x26,
USB_KEY_0 = 0x27,
USB_KEY_RETURN = 0x28,
USB_KEY_ESC = 0x29,
USB_KEY_BACKSPACE = 0x2A,
USB_KEY_TAB = 0x2B,
USB_KEY_SPACE = 0x2C,
USB_KEY_DASH = 0x2D,
USB_KEY_EQUALS = 0x2E,
USB_KEY_OPEN_BRACKET = 0x2F,
USB_KEY_CLOSE_BRACKET = 0x30,
USB_KEY_ANSI_BACKSLASH = 0x31,
USB_KEY_INT_NEXT_TO_RETURN = 0x32,
USB_KEY_SEMICOLON = 0x33,
USB_KEY_QUOTE = 0x34,
USB_KEY_BACKTICK = 0x35,
USB_KEY_COMMA = 0x36,
USB_KEY_PERIOD = 0x37,
USB_KEY_SLASH = 0x38,
USB_KEY_BACKSLASH = USB_KEY_ANSI_BACKSLASH,
USB_KEY_MINUS = USB_KEY_DASH,
USB_KEY_CAPS_LOCK = 0x39,
USB_KEY_F1 = 0x3A,
USB_KEY_F2 = 0x3B,
USB_KEY_F3 = 0x3C,
USB_KEY_F4 = 0x3D,
USB_KEY_F5 = 0x3E,
USB_KEY_F6 = 0x3F,
USB_KEY_F7 = 0x40,
USB_KEY_F8 = 0x41,
USB_KEY_F9 = 0x42,
USB_KEY_F10 = 0x43,
USB_KEY_F11 = 0x44,
USB_KEY_F12 = 0x45,
USB_KEY_PRINT_SCREEN = 0x46,
USB_KEY_SCROLL_LOCK = 0x47,
USB_KEY_PAUSE_BREAK = 0x48,
USB_KEY_PAUSE = USB_KEY_PAUSE_BREAK,
USB_KEY_INSERT = 0x49,
USB_KEY_HOME = 0x4A,
USB_KEY_PAGE_UP = 0x4B,
USB_KEY_DELETE = 0x4C,
USB_KEY_END = 0x4D,
USB_KEY_PAGE_DOWN = 0x4E,
USB_KEY_RIGHT_ARROW = 0x4F,
USB_KEY_LEFT_ARROW = 0x50,
USB_KEY_DOWN_ARROW = 0x51,
USB_KEY_UP_ARROW = 0x52,
USB_KEY_NUM_LOCK = 0x53,
USB_KEY_KP_DIVIDE = 0x54,
USB_KEY_KP_MULTIPLY = 0x55,
USB_KEY_KP_MINUS = 0x56,
USB_KEY_KP_PLUS = 0x57,
USB_KEY_KP_ENTER = 0x58,
USB_KEY_KP_1_END = 0x59,
USB_KEY_KP_2_DOWN = 0x5A,
USB_KEY_KP_3_PAGE_DOWN = 0x5B,
USB_KEY_KP_4_LEFT = 0x5C,
USB_KEY_KP_5 = 0x5D,
USB_KEY_KP_6_RIGHT = 0x5E,
USB_KEY_KP_7_HOME = 0x5F,
USB_KEY_KP_8_UP = 0x60,
USB_KEY_KP_9_PAGE_UP = 0x61,
USB_KEY_KP_0_INSERT = 0x62,
USB_KEY_KP_COMMA_DEL = 0x63,
USB_KEY_KP_EQUALS = 0x67,
USB_KEY_KP_COMMA = USB_KEY_KP_COMMA_DEL,
USB_KEY_KP_PERIOD = USB_KEY_KP_COMMA_DEL,
USB_KEY_KP_DOT = USB_KEY_KP_COMMA_DEL,
USB_KEY_KP_1 = USB_KEY_KP_1_END,
USB_KEY_KP_2 = USB_KEY_KP_2_DOWN,
USB_KEY_KP_3 = USB_KEY_KP_3_PAGE_DOWN,
USB_KEY_KP_4 = USB_KEY_KP_4_LEFT,
USB_KEY_KP_6 = USB_KEY_KP_6_RIGHT,
USB_KEY_KP_7 = USB_KEY_KP_7_HOME,
USB_KEY_KP_8 = USB_KEY_KP_8_UP,
USB_KEY_KP_9 = USB_KEY_KP_9_PAGE_UP,
USB_KEY_KP_0 = USB_KEY_KP_0_INSERT,
USB_KEY_INT_NEXT_TO_LEFT_SHIFT = 0x64,
USB_KEY_MENU = 0x65,
USB_KEY_APPLICATION = USB_KEY_MENU,
USB_KEY_POWER = 0x66,
USB_KEY_F13 = 0x68,
USB_KEY_F14 = 0x69,
USB_KEY_F15 = 0x6A,
USB_KEY_F16 = 0x6B,
USB_KEY_F17 = 0x6C,
USB_KEY_F18 = 0x6D,
USB_KEY_F19 = 0x6E,
USB_KEY_F20 = 0x6F,
USB_KEY_F21 = 0x70,
USB_KEY_F22 = 0x71,
USB_KEY_F23 = 0x72,
USB_KEY_F24 = 0x73,
USB_KEY_EXECUTE = 0x74,
USB_KEY_HELP = 0x75,
USB_KEY_CLASSIC_MENU = 0x76, // Not Win-Menu
USB_KEY_SELECT = 0x77,
USB_KEY_STOP = 0x78,
USB_KEY_AGAIN = 0x79,
USB_KEY_UNDO = 0x7A,
USB_KEY_CUT = 0x7B,
USB_KEY_COPY = 0x7C,
USB_KEY_PASTE = 0x7D,
USB_KEY_FIND = 0x7E,
USB_KEY_MUTE = 0x7F,
// - MARK: - 8-bit keycodes
USB_KEY_VOLUME_UP = 0x80,
USB_KEY_VOLUME_DOWN = 0x81,
USB_KEY_LOCKING_CAPS_LOCK = 0x82,
USB_KEY_LOCKING_NUM_LOCK = 0x83,
USB_KEY_LOCKING_SCROLL_LOCK = 0x84,
USB_KEY_KP_BRAZILIAN_PERIOD = 0x85,
USB_KEY_KP_EQUALS_AS400 = 0x86,
USB_KEY_INT_LEFT_OF_RIGHT_SHIFT = 0x87,
USB_KEY_KATAKANA = 0x88,
USB_KEY_INT_LEFT_OF_BACKSPACE = 0x89,
USB_KEY_KANJI = 0x8A,
USB_KEY_HIRAGANA = 0x8B,
USB_KEY_ALT_ERASE = 0x99,
USB_KEY_SYSRQ = 0x9A,
USB_KEY_CANCEL = 0x9B,
USB_KEY_CLEAR = 0x9C,
USB_KEY_PRIOR = 0x9D,
USB_KEY_RETURN2 = 0x9E,
USB_KEY_SEPARATOR = 0x9F,
USB_KEY_OUT = 0xA0,
USB_KEY_OPER = 0xA1,
USB_KEY_CLEAR_AGAIN = 0xA2,
USB_KEY_CRSEL_PROPS = 0xA3,
USB_KEY_KP_00 = 0xB0,
USB_KEY_KP_000 = 0xB1,
USB_KEY_THOUSANDS_SEPARATOR = 0xB2,
USB_KEY_DECIMAL_SEPARATOR = 0xB3,
USB_KEY_CURRENCY_UNIT = 0xB4,
USB_KEY_CURRENCY_SUB_UNIT = 0xB5,
USB_KEY_KP_OPEN_PAREN = 0xB6,
USB_KEY_KP_CLOSE_PAREN = 0xB7,
USB_KEY_KP_OPEN_BRACKET = 0xB8,
USB_KEY_KP_CLOSE_BRACKET = 0xB9,
USB_KEY_KP_TAB = 0xBA,
USB_KEY_KP_BACKSPACE = 0xBB,
USB_KEY_KP_A = 0xBC,
USB_KEY_KP_B = 0xBD,
USB_KEY_KP_C = 0xBE,
USB_KEY_KP_D = 0xBF,
USB_KEY_KP_E = 0xC0,
USB_KEY_KP_F = 0xC1,
USB_KEY_KP_XOR = 0xC2,
USB_KEY_KP_CIRCUMFLEX = 0xC3,
USB_KEY_KP_PERCENT = 0xC4,
USB_KEY_KP_LESS_THAN = 0xC5,
USB_KEY_KP_GREATER_THAN = 0xC6,
USB_KEY_KP_AMPERSAND = 0xC7,
USB_KEY_KP_DOUBLE_AMPERSAND = 0xC8,
USB_KEY_KP_PIPE = 0xC9,
USB_KEY_KP_DOUBLE_PIPE = 0xCA,
USB_KEY_KP_COLON = 0xCB,
USB_KEY_KP_HASH = 0xCC,
USB_KEY_KP_SPACE = 0xCD,
USB_KEY_KP_AT = 0xCE,
USB_KEY_KP_EXCLAMATION = 0xCF,
USB_KEY_KP_MS = 0xD0,
USB_KEY_KP_MR = 0xD1,
USB_KEY_KP_MC = 0xD2,
USB_KEY_KP_MADD = 0xD3,
USB_KEY_KP_MSUB = 0xD4,
USB_KEY_KP_MMUL = 0xD5,
USB_KEY_KP_MDIV = 0xD6,
USB_KEY_KP_PLUS_MINUS = 0xD7,
USB_KEY_KP_CLEAR = 0xD8,
USB_KEY_KP_CLEAR_ENTRY = 0xD9,
USB_KEY_KP_BINARY = 0xDA,
USB_KEY_KP_OCTAL = 0xDB,
USB_KEY_KP_DECIMAL = 0xDC,
USB_KEY_KP_HEXADECIMAL = 0xDD,
USB_KEY_LEFT_CTRL = 0xE0,
USB_KEY_LEFT_SHIFT = 0xE1,
USB_KEY_LEFT_ALT = 0xE2,
USB_KEY_LEFT_WIN = 0xE3,
USB_KEY_RIGHT_CTRL = 0xE4,
USB_KEY_RIGHT_SHIFT = 0xE5,
USB_KEY_RIGHT_ALT = 0xE6,
USB_KEY_RIGHT_WIN = 0xE7,
// Aliases
USB_KEY_ALT = USB_KEY_LEFT_ALT,
USB_KEY_SHIFT = USB_KEY_LEFT_SHIFT,
USB_KEY_CTRL = USB_KEY_LEFT_CTRL,
USB_KEY_WIN = USB_KEY_LEFT_WIN,
USB_KEY_CMD = USB_KEY_LEFT_WIN,
USB_KEY_META = USB_KEY_LEFT_WIN,
USB_KEY_ALTGR = USB_KEY_RIGHT_ALT,
USB_KEY_ALT_GR = USB_KEY_RIGHT_ALT,
USB_KEY_LEFT_CMD = USB_KEY_LEFT_WIN,
USB_KEY_RIGHT_CMD = USB_KEY_RIGHT_WIN,
USB_KEY_LEFT_META = USB_KEY_LEFT_WIN,
USB_KEY_RIGHT_META = USB_KEY_RIGHT_WIN,
USB_KEY_LEFT_GUI = USB_KEY_LEFT_WIN,
USB_KEY_RIGHT_GUI = USB_KEY_RIGHT_WIN,
// MARK: - Dvorak mappings
// Number row
USB_KEY_DVORAK_OPEN_BRACKET = USB_KEY_DASH,
USB_KEY_DVORAK_CLOSE_BRACKET = USB_KEY_EQUALS,
// Top row
USB_KEY_DVORAK_QUOTE = USB_KEY_Q,
USB_KEY_DVORAK_COMMA = USB_KEY_W,
USB_KEY_DVORAK_PERIOD = USB_KEY_E,
USB_KEY_DVORAK_P = USB_KEY_R,
USB_KEY_DVORAK_Y = USB_KEY_T,
USB_KEY_DVORAK_F = USB_KEY_Y,
USB_KEY_DVORAK_G = USB_KEY_U,
USB_KEY_DVORAK_C = USB_KEY_I,
USB_KEY_DVORAK_R = USB_KEY_O,
USB_KEY_DVORAK_L = USB_KEY_P,
USB_KEY_DVORAK_SLASH = USB_KEY_OPEN_BRACKET,
USB_KEY_DVORAK_EQUALS = USB_KEY_CLOSE_BRACKET,
// Home row
USB_KEY_DVORAK_A = USB_KEY_A,
USB_KEY_DVORAK_O = USB_KEY_S,
USB_KEY_DVORAK_E = USB_KEY_D,
USB_KEY_DVORAK_U = USB_KEY_F,
USB_KEY_DVORAK_I = USB_KEY_G,
USB_KEY_DVORAK_D = USB_KEY_H,
USB_KEY_DVORAK_H = USB_KEY_J,
USB_KEY_DVORAK_T = USB_KEY_K,
USB_KEY_DVORAK_N = USB_KEY_L,
USB_KEY_DVORAK_S = USB_KEY_SEMICOLON,
USB_KEY_DVORAK_DASH = USB_KEY_QUOTE,
// Bottom row
USB_KEY_DVORAK_SEMICOLON = USB_KEY_Z,
USB_KEY_DVORAK_Q = USB_KEY_X,
USB_KEY_DVORAK_J = USB_KEY_C,
USB_KEY_DVORAK_K = USB_KEY_V,
USB_KEY_DVORAK_X = USB_KEY_B,
USB_KEY_DVORAK_B = USB_KEY_N,
USB_KEY_DVORAK_M = USB_KEY_M,
USB_KEY_DVORAK_W = USB_KEY_COMMA,
USB_KEY_DVORAK_V = USB_KEY_PERIOD,
USB_KEY_DVORAK_Z = USB_KEY_SLASH,
// MARK: - Virtual keys (these need special support)
// Requires the use of Apple's vendor id and a separate byte in the
// report descriptor (usage page 0xFF, usage 0x03, 1 = pressed).
USB_KEY_VIRTUAL_APPLE_FN = (USB_KEY_RIGHT_CMD + 1),
USB_KEY_VIRTUAL_APPLE_BRIGHTNESS_UP,
USB_KEY_VIRTUAL_APPLE_BRIGHTNESS_DOWN,
USB_KEY_VIRTUAL_APPLE_SPOTLIGHT,
USB_KEY_VIRTUAL_APPLE_DASHBOARD,
USB_KEY_VIRTUAL_APPLE_LAUNCHPAD,
USB_KEY_VIRTUAL_APPLE_EXPOSE,
USB_KEY_VIRTUAL_APPLE_EXPOSE_DESKTOP,
};
enum usb_consumer_control {
CC_KEY_MEDIA_FAST_FORWARD = 0xB5,
CC_KEY_MEDIA_REWIND = 0xB6,
CC_KEY_MEDIA_STOP = 0xB7,
CC_KEY_MEDIA_EJECT = 0xB8,
CC_KEY_MEDIA_PLAY_PAUSE = 0xCD,
CC_KEY_MEDIA_MUTE = 0xE2,
CC_KEY_MEDIA_VOLUME_UP = 0xE9,
CC_KEY_MEDIA_VOLUME_DOWN = 0xEA,
};
// MARK: - Modifiers
#define MODIFIERS_START USB_KEY_LEFT_CTRL
#define MODIFIERS_END USB_KEY_RIGHT_WIN
#define MODIFIER_COUNT ((MODIFIERS_END - MODIFIERS_START) + 1)
#define MODIFIER_BIT(key) (1U << ((key) - MODIFIERS_START))
#define SHIFT_BIT MODIFIER_BIT(USB_KEY_SHIFT)
#define ALT_BIT MODIFIER_BIT(USB_KEY_ALT)
#define CTRL_BIT MODIFIER_BIT(USB_KEY_CTRL)
#define CMD_BIT MODIFIER_BIT(USB_KEY_CMD)
#define WIN_BIT MODIFIER_BIT(USB_KEY_WIN)
#define META_BIT MODIFIER_BIT(USB_KEY_META)
#define ALTGR_BIT MODIFIER_BIT(USB_KEY_RIGHT_ALT)
#define RIGHT_SHIFT_BIT MODIFIER_BIT(USB_KEY_RIGHT_SHIFT)
#define RIGHT_CTRL_BIT MODIFIER_BIT(USB_KEY_RIGHT_CTRL)
#define RIGHT_ALT_BIT MODIFIER_BIT(USB_KEY_RIGHT_ALT)
#define RIGHT_CMD_BIT MODIFIER_BIT(USB_KEY_RIGHT_CMD)
#define RIGHT_WIN_BIT MODIFIER_BIT(USB_KEY_RIGHT_WIN)
#define RIGHT_META_BIT MODIFIER_BIT(USB_KEY_RIGHT_META)
#define LEFT_SHIFT_BIT MODIFIER_BIT(USB_KEY_SHIFT)
#define LEFT_ALT_BIT MODIFIER_BIT(USB_KEY_ALT)
#define LEFT_CTRL_BIT MODIFIER_BIT(USB_KEY_CTRL)
#define LEFT_CMD_BIT MODIFIER_BIT(USB_KEY_CMD)
#define LEFT_WIN_BIT MODIFIER_BIT(USB_KEY_WIN)
#define LEFT_META_BIT MODIFIER_BIT(USB_KEY_META)
#define IS_MODIFIER(key) ((key) >= MODIFIERS_START && (key) <= MODIFIERS_END)
#endif