InputEventLabels.h revision e7a57d128038492445caac998d55983fb6085dfa
1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef _LIBINPUT_INPUT_EVENT_LABELS_H
18#define _LIBINPUT_INPUT_EVENT_LABELS_H
19
20#include <input/Input.h>
21#include <android/keycodes.h>
22
23#define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
24#define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
25#define DEFINE_LED(led) { #led, ALED_##led }
26#define DEFINE_FLAG(flag) { #flag, POLICY_FLAG_##flag }
27
28namespace android {
29
30template<typename T, size_t N>
31size_t size(T (&)[N]) { return N; }
32
33struct InputEventLabel {
34    const char *literal;
35    int value;
36};
37
38
39static const InputEventLabel KEYCODES[] = {
40    // NOTE: If you add a new keycode here you must also add it to several other files.
41    //       Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
42    DEFINE_KEYCODE(UNKNOWN),
43    DEFINE_KEYCODE(SOFT_LEFT),
44    DEFINE_KEYCODE(SOFT_RIGHT),
45    DEFINE_KEYCODE(HOME),
46    DEFINE_KEYCODE(BACK),
47    DEFINE_KEYCODE(CALL),
48    DEFINE_KEYCODE(ENDCALL),
49    DEFINE_KEYCODE(0),
50    DEFINE_KEYCODE(1),
51    DEFINE_KEYCODE(2),
52    DEFINE_KEYCODE(3),
53    DEFINE_KEYCODE(4),
54    DEFINE_KEYCODE(5),
55    DEFINE_KEYCODE(6),
56    DEFINE_KEYCODE(7),
57    DEFINE_KEYCODE(8),
58    DEFINE_KEYCODE(9),
59    DEFINE_KEYCODE(STAR),
60    DEFINE_KEYCODE(POUND),
61    DEFINE_KEYCODE(DPAD_UP),
62    DEFINE_KEYCODE(DPAD_DOWN),
63    DEFINE_KEYCODE(DPAD_LEFT),
64    DEFINE_KEYCODE(DPAD_RIGHT),
65    DEFINE_KEYCODE(DPAD_CENTER),
66    DEFINE_KEYCODE(VOLUME_UP),
67    DEFINE_KEYCODE(VOLUME_DOWN),
68    DEFINE_KEYCODE(POWER),
69    DEFINE_KEYCODE(CAMERA),
70    DEFINE_KEYCODE(CLEAR),
71    DEFINE_KEYCODE(A),
72    DEFINE_KEYCODE(B),
73    DEFINE_KEYCODE(C),
74    DEFINE_KEYCODE(D),
75    DEFINE_KEYCODE(E),
76    DEFINE_KEYCODE(F),
77    DEFINE_KEYCODE(G),
78    DEFINE_KEYCODE(H),
79    DEFINE_KEYCODE(I),
80    DEFINE_KEYCODE(J),
81    DEFINE_KEYCODE(K),
82    DEFINE_KEYCODE(L),
83    DEFINE_KEYCODE(M),
84    DEFINE_KEYCODE(N),
85    DEFINE_KEYCODE(O),
86    DEFINE_KEYCODE(P),
87    DEFINE_KEYCODE(Q),
88    DEFINE_KEYCODE(R),
89    DEFINE_KEYCODE(S),
90    DEFINE_KEYCODE(T),
91    DEFINE_KEYCODE(U),
92    DEFINE_KEYCODE(V),
93    DEFINE_KEYCODE(W),
94    DEFINE_KEYCODE(X),
95    DEFINE_KEYCODE(Y),
96    DEFINE_KEYCODE(Z),
97    DEFINE_KEYCODE(COMMA),
98    DEFINE_KEYCODE(PERIOD),
99    DEFINE_KEYCODE(ALT_LEFT),
100    DEFINE_KEYCODE(ALT_RIGHT),
101    DEFINE_KEYCODE(SHIFT_LEFT),
102    DEFINE_KEYCODE(SHIFT_RIGHT),
103    DEFINE_KEYCODE(TAB),
104    DEFINE_KEYCODE(SPACE),
105    DEFINE_KEYCODE(SYM),
106    DEFINE_KEYCODE(EXPLORER),
107    DEFINE_KEYCODE(ENVELOPE),
108    DEFINE_KEYCODE(ENTER),
109    DEFINE_KEYCODE(DEL),
110    DEFINE_KEYCODE(GRAVE),
111    DEFINE_KEYCODE(MINUS),
112    DEFINE_KEYCODE(EQUALS),
113    DEFINE_KEYCODE(LEFT_BRACKET),
114    DEFINE_KEYCODE(RIGHT_BRACKET),
115    DEFINE_KEYCODE(BACKSLASH),
116    DEFINE_KEYCODE(SEMICOLON),
117    DEFINE_KEYCODE(APOSTROPHE),
118    DEFINE_KEYCODE(SLASH),
119    DEFINE_KEYCODE(AT),
120    DEFINE_KEYCODE(NUM),
121    DEFINE_KEYCODE(HEADSETHOOK),
122    DEFINE_KEYCODE(FOCUS),   // *Camera* focus
123    DEFINE_KEYCODE(PLUS),
124    DEFINE_KEYCODE(MENU),
125    DEFINE_KEYCODE(NOTIFICATION),
126    DEFINE_KEYCODE(SEARCH),
127    DEFINE_KEYCODE(MEDIA_PLAY_PAUSE),
128    DEFINE_KEYCODE(MEDIA_STOP),
129    DEFINE_KEYCODE(MEDIA_NEXT),
130    DEFINE_KEYCODE(MEDIA_PREVIOUS),
131    DEFINE_KEYCODE(MEDIA_REWIND),
132    DEFINE_KEYCODE(MEDIA_FAST_FORWARD),
133    DEFINE_KEYCODE(MUTE),
134    DEFINE_KEYCODE(PAGE_UP),
135    DEFINE_KEYCODE(PAGE_DOWN),
136    DEFINE_KEYCODE(PICTSYMBOLS),
137    DEFINE_KEYCODE(SWITCH_CHARSET),
138    DEFINE_KEYCODE(BUTTON_A),
139    DEFINE_KEYCODE(BUTTON_B),
140    DEFINE_KEYCODE(BUTTON_C),
141    DEFINE_KEYCODE(BUTTON_X),
142    DEFINE_KEYCODE(BUTTON_Y),
143    DEFINE_KEYCODE(BUTTON_Z),
144    DEFINE_KEYCODE(BUTTON_L1),
145    DEFINE_KEYCODE(BUTTON_R1),
146    DEFINE_KEYCODE(BUTTON_L2),
147    DEFINE_KEYCODE(BUTTON_R2),
148    DEFINE_KEYCODE(BUTTON_THUMBL),
149    DEFINE_KEYCODE(BUTTON_THUMBR),
150    DEFINE_KEYCODE(BUTTON_START),
151    DEFINE_KEYCODE(BUTTON_SELECT),
152    DEFINE_KEYCODE(BUTTON_MODE),
153    DEFINE_KEYCODE(ESCAPE),
154    DEFINE_KEYCODE(FORWARD_DEL),
155    DEFINE_KEYCODE(CTRL_LEFT),
156    DEFINE_KEYCODE(CTRL_RIGHT),
157    DEFINE_KEYCODE(CAPS_LOCK),
158    DEFINE_KEYCODE(SCROLL_LOCK),
159    DEFINE_KEYCODE(META_LEFT),
160    DEFINE_KEYCODE(META_RIGHT),
161    DEFINE_KEYCODE(FUNCTION),
162    DEFINE_KEYCODE(SYSRQ),
163    DEFINE_KEYCODE(BREAK),
164    DEFINE_KEYCODE(MOVE_HOME),
165    DEFINE_KEYCODE(MOVE_END),
166    DEFINE_KEYCODE(INSERT),
167    DEFINE_KEYCODE(FORWARD),
168    DEFINE_KEYCODE(MEDIA_PLAY),
169    DEFINE_KEYCODE(MEDIA_PAUSE),
170    DEFINE_KEYCODE(MEDIA_CLOSE),
171    DEFINE_KEYCODE(MEDIA_EJECT),
172    DEFINE_KEYCODE(MEDIA_RECORD),
173    DEFINE_KEYCODE(F1),
174    DEFINE_KEYCODE(F2),
175    DEFINE_KEYCODE(F3),
176    DEFINE_KEYCODE(F4),
177    DEFINE_KEYCODE(F5),
178    DEFINE_KEYCODE(F6),
179    DEFINE_KEYCODE(F7),
180    DEFINE_KEYCODE(F8),
181    DEFINE_KEYCODE(F9),
182    DEFINE_KEYCODE(F10),
183    DEFINE_KEYCODE(F11),
184    DEFINE_KEYCODE(F12),
185    DEFINE_KEYCODE(NUM_LOCK),
186    DEFINE_KEYCODE(NUMPAD_0),
187    DEFINE_KEYCODE(NUMPAD_1),
188    DEFINE_KEYCODE(NUMPAD_2),
189    DEFINE_KEYCODE(NUMPAD_3),
190    DEFINE_KEYCODE(NUMPAD_4),
191    DEFINE_KEYCODE(NUMPAD_5),
192    DEFINE_KEYCODE(NUMPAD_6),
193    DEFINE_KEYCODE(NUMPAD_7),
194    DEFINE_KEYCODE(NUMPAD_8),
195    DEFINE_KEYCODE(NUMPAD_9),
196    DEFINE_KEYCODE(NUMPAD_DIVIDE),
197    DEFINE_KEYCODE(NUMPAD_MULTIPLY),
198    DEFINE_KEYCODE(NUMPAD_SUBTRACT),
199    DEFINE_KEYCODE(NUMPAD_ADD),
200    DEFINE_KEYCODE(NUMPAD_DOT),
201    DEFINE_KEYCODE(NUMPAD_COMMA),
202    DEFINE_KEYCODE(NUMPAD_ENTER),
203    DEFINE_KEYCODE(NUMPAD_EQUALS),
204    DEFINE_KEYCODE(NUMPAD_LEFT_PAREN),
205    DEFINE_KEYCODE(NUMPAD_RIGHT_PAREN),
206    DEFINE_KEYCODE(VOLUME_MUTE),
207    DEFINE_KEYCODE(INFO),
208    DEFINE_KEYCODE(CHANNEL_UP),
209    DEFINE_KEYCODE(CHANNEL_DOWN),
210    DEFINE_KEYCODE(ZOOM_IN),
211    DEFINE_KEYCODE(ZOOM_OUT),
212    DEFINE_KEYCODE(TV),
213    DEFINE_KEYCODE(WINDOW),
214    DEFINE_KEYCODE(GUIDE),
215    DEFINE_KEYCODE(DVR),
216    DEFINE_KEYCODE(BOOKMARK),
217    DEFINE_KEYCODE(CAPTIONS),
218    DEFINE_KEYCODE(SETTINGS),
219    DEFINE_KEYCODE(TV_POWER),
220    DEFINE_KEYCODE(TV_INPUT),
221    DEFINE_KEYCODE(STB_POWER),
222    DEFINE_KEYCODE(STB_INPUT),
223    DEFINE_KEYCODE(AVR_POWER),
224    DEFINE_KEYCODE(AVR_INPUT),
225    DEFINE_KEYCODE(PROG_RED),
226    DEFINE_KEYCODE(PROG_GREEN),
227    DEFINE_KEYCODE(PROG_YELLOW),
228    DEFINE_KEYCODE(PROG_BLUE),
229    DEFINE_KEYCODE(APP_SWITCH),
230    DEFINE_KEYCODE(BUTTON_1),
231    DEFINE_KEYCODE(BUTTON_2),
232    DEFINE_KEYCODE(BUTTON_3),
233    DEFINE_KEYCODE(BUTTON_4),
234    DEFINE_KEYCODE(BUTTON_5),
235    DEFINE_KEYCODE(BUTTON_6),
236    DEFINE_KEYCODE(BUTTON_7),
237    DEFINE_KEYCODE(BUTTON_8),
238    DEFINE_KEYCODE(BUTTON_9),
239    DEFINE_KEYCODE(BUTTON_10),
240    DEFINE_KEYCODE(BUTTON_11),
241    DEFINE_KEYCODE(BUTTON_12),
242    DEFINE_KEYCODE(BUTTON_13),
243    DEFINE_KEYCODE(BUTTON_14),
244    DEFINE_KEYCODE(BUTTON_15),
245    DEFINE_KEYCODE(BUTTON_16),
246    DEFINE_KEYCODE(LANGUAGE_SWITCH),
247    DEFINE_KEYCODE(MANNER_MODE),
248    DEFINE_KEYCODE(3D_MODE),
249    DEFINE_KEYCODE(CONTACTS),
250    DEFINE_KEYCODE(CALENDAR),
251    DEFINE_KEYCODE(MUSIC),
252    DEFINE_KEYCODE(CALCULATOR),
253    DEFINE_KEYCODE(ZENKAKU_HANKAKU),
254    DEFINE_KEYCODE(EISU),
255    DEFINE_KEYCODE(MUHENKAN),
256    DEFINE_KEYCODE(HENKAN),
257    DEFINE_KEYCODE(KATAKANA_HIRAGANA),
258    DEFINE_KEYCODE(YEN),
259    DEFINE_KEYCODE(RO),
260    DEFINE_KEYCODE(KANA),
261    DEFINE_KEYCODE(ASSIST),
262    DEFINE_KEYCODE(BRIGHTNESS_DOWN),
263    DEFINE_KEYCODE(BRIGHTNESS_UP),
264    DEFINE_KEYCODE(MEDIA_AUDIO_TRACK),
265    DEFINE_KEYCODE(SLEEP),
266    DEFINE_KEYCODE(WAKEUP),
267    DEFINE_KEYCODE(PAIRING),
268    DEFINE_KEYCODE(MEDIA_TOP_MENU),
269    DEFINE_KEYCODE(11),
270    DEFINE_KEYCODE(12),
271    DEFINE_KEYCODE(LAST_CHANNEL),
272    DEFINE_KEYCODE(TV_DATA_SERVICE),
273    DEFINE_KEYCODE(VOICE_ASSIST),
274    DEFINE_KEYCODE(TV_RADIO_SERVICE),
275    DEFINE_KEYCODE(TV_TELETEXT),
276    DEFINE_KEYCODE(TV_NUMBER_ENTRY),
277    DEFINE_KEYCODE(TV_TERRESTRIAL_ANALOG),
278    DEFINE_KEYCODE(TV_TERRESTRIAL_DIGITAL),
279    DEFINE_KEYCODE(TV_SATELLITE),
280    DEFINE_KEYCODE(TV_SATELLITE_BS),
281    DEFINE_KEYCODE(TV_SATELLITE_CS),
282    DEFINE_KEYCODE(TV_SATELLITE_SERVICE),
283    DEFINE_KEYCODE(TV_NETWORK),
284    DEFINE_KEYCODE(TV_ANTENNA_CABLE),
285    DEFINE_KEYCODE(TV_INPUT_HDMI_1),
286    DEFINE_KEYCODE(TV_INPUT_HDMI_2),
287    DEFINE_KEYCODE(TV_INPUT_HDMI_3),
288    DEFINE_KEYCODE(TV_INPUT_HDMI_4),
289    DEFINE_KEYCODE(TV_INPUT_COMPOSITE_1),
290    DEFINE_KEYCODE(TV_INPUT_COMPOSITE_2),
291    DEFINE_KEYCODE(TV_INPUT_COMPONENT_1),
292    DEFINE_KEYCODE(TV_INPUT_COMPONENT_2),
293    DEFINE_KEYCODE(TV_INPUT_VGA_1),
294    DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION),
295    DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_UP),
296    DEFINE_KEYCODE(TV_AUDIO_DESCRIPTION_MIX_DOWN),
297    DEFINE_KEYCODE(TV_ZOOM_MODE),
298    DEFINE_KEYCODE(TV_CONTENTS_MENU),
299    DEFINE_KEYCODE(TV_MEDIA_CONTEXT_MENU),
300    DEFINE_KEYCODE(TV_TIMER_PROGRAMMING),
301    DEFINE_KEYCODE(HELP),
302    DEFINE_KEYCODE(NAVIGATE_PREVIOUS),
303    DEFINE_KEYCODE(NAVIGATE_NEXT),
304    DEFINE_KEYCODE(NAVIGATE_IN),
305    DEFINE_KEYCODE(NAVIGATE_OUT),
306    DEFINE_KEYCODE(STEM_PRIMARY),
307    DEFINE_KEYCODE(STEM_1),
308    DEFINE_KEYCODE(STEM_2),
309    DEFINE_KEYCODE(STEM_3),
310    DEFINE_KEYCODE(DPAD_UP_LEFT),
311    DEFINE_KEYCODE(DPAD_DOWN_LEFT),
312    DEFINE_KEYCODE(DPAD_UP_RIGHT),
313    DEFINE_KEYCODE(DPAD_DOWN_RIGHT),
314    DEFINE_KEYCODE(MEDIA_SKIP_FORWARD),
315    DEFINE_KEYCODE(MEDIA_SKIP_BACKWARD),
316    DEFINE_KEYCODE(MEDIA_STEP_FORWARD),
317    DEFINE_KEYCODE(MEDIA_STEP_BACKWARD),
318    DEFINE_KEYCODE(SOFT_SLEEP),
319    DEFINE_KEYCODE(CUT),
320    DEFINE_KEYCODE(COPY),
321    DEFINE_KEYCODE(PASTE),
322    DEFINE_KEYCODE(SYSTEM_NAVIGATION_UP),
323    DEFINE_KEYCODE(SYSTEM_NAVIGATION_DOWN),
324    DEFINE_KEYCODE(SYSTEM_NAVIGATION_LEFT),
325    DEFINE_KEYCODE(SYSTEM_NAVIGATION_RIGHT),
326
327    { NULL, 0 }
328};
329
330static const InputEventLabel AXES[] = {
331    DEFINE_AXIS(X),
332    DEFINE_AXIS(Y),
333    DEFINE_AXIS(PRESSURE),
334    DEFINE_AXIS(SIZE),
335    DEFINE_AXIS(TOUCH_MAJOR),
336    DEFINE_AXIS(TOUCH_MINOR),
337    DEFINE_AXIS(TOOL_MAJOR),
338    DEFINE_AXIS(TOOL_MINOR),
339    DEFINE_AXIS(ORIENTATION),
340    DEFINE_AXIS(VSCROLL),
341    DEFINE_AXIS(HSCROLL),
342    DEFINE_AXIS(Z),
343    DEFINE_AXIS(RX),
344    DEFINE_AXIS(RY),
345    DEFINE_AXIS(RZ),
346    DEFINE_AXIS(HAT_X),
347    DEFINE_AXIS(HAT_Y),
348    DEFINE_AXIS(LTRIGGER),
349    DEFINE_AXIS(RTRIGGER),
350    DEFINE_AXIS(THROTTLE),
351    DEFINE_AXIS(RUDDER),
352    DEFINE_AXIS(WHEEL),
353    DEFINE_AXIS(GAS),
354    DEFINE_AXIS(BRAKE),
355    DEFINE_AXIS(DISTANCE),
356    DEFINE_AXIS(TILT),
357    DEFINE_AXIS(GENERIC_1),
358    DEFINE_AXIS(GENERIC_2),
359    DEFINE_AXIS(GENERIC_3),
360    DEFINE_AXIS(GENERIC_4),
361    DEFINE_AXIS(GENERIC_5),
362    DEFINE_AXIS(GENERIC_6),
363    DEFINE_AXIS(GENERIC_7),
364    DEFINE_AXIS(GENERIC_8),
365    DEFINE_AXIS(GENERIC_9),
366    DEFINE_AXIS(GENERIC_10),
367    DEFINE_AXIS(GENERIC_11),
368    DEFINE_AXIS(GENERIC_12),
369    DEFINE_AXIS(GENERIC_13),
370    DEFINE_AXIS(GENERIC_14),
371    DEFINE_AXIS(GENERIC_15),
372    DEFINE_AXIS(GENERIC_16),
373
374    // NOTE: If you add a new axis here you must also add it to several other files.
375    //       Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
376    { NULL, 0 }
377};
378
379static const InputEventLabel LEDS[] = {
380    DEFINE_LED(NUM_LOCK),
381    DEFINE_LED(CAPS_LOCK),
382    DEFINE_LED(SCROLL_LOCK),
383    DEFINE_LED(COMPOSE),
384    DEFINE_LED(KANA),
385    DEFINE_LED(SLEEP),
386    DEFINE_LED(SUSPEND),
387    DEFINE_LED(MUTE),
388    DEFINE_LED(MISC),
389    DEFINE_LED(MAIL),
390    DEFINE_LED(CHARGING),
391    DEFINE_LED(CONTROLLER_1),
392    DEFINE_LED(CONTROLLER_2),
393    DEFINE_LED(CONTROLLER_3),
394    DEFINE_LED(CONTROLLER_4),
395
396    // NOTE: If you add new LEDs here, you must also add them to Input.h
397    { NULL, 0 }
398};
399
400static const InputEventLabel FLAGS[] = {
401    DEFINE_FLAG(VIRTUAL),
402    DEFINE_FLAG(FUNCTION),
403    DEFINE_FLAG(GESTURE),
404
405    { NULL, 0 }
406};
407
408static int lookupValueByLabel(const char* literal, const InputEventLabel *list) {
409    while (list->literal) {
410        if (strcmp(literal, list->literal) == 0) {
411            return list->value;
412        }
413        list++;
414    }
415    return list->value;
416}
417
418static const char* lookupLabelByValue(int value, const InputEventLabel* list) {
419    while (list->literal) {
420        if (list->value == value) {
421            return list->literal;
422        }
423        list++;
424    }
425    return NULL;
426}
427
428static int32_t getKeyCodeByLabel(const char* label) {
429    return int32_t(lookupValueByLabel(label, KEYCODES));
430}
431
432static const char* getLabelByKeyCode(int32_t keyCode) {
433    if (keyCode >= 0 && keyCode < size(KEYCODES)) {
434        return KEYCODES[keyCode].literal;
435    }
436    return NULL;
437}
438
439static uint32_t getKeyFlagByLabel(const char* label) {
440    return uint32_t(lookupValueByLabel(label, FLAGS));
441}
442
443static int32_t getAxisByLabel(const char* label) {
444    return int32_t(lookupValueByLabel(label, AXES));
445}
446
447static const char* getAxisLabel(int32_t axisId) {
448    return lookupLabelByValue(axisId, AXES);
449}
450
451static int32_t getLedByLabel(const char* label) {
452    return int32_t(lookupValueByLabel(label, LEDS));
453}
454
455
456} // namespace android
457#endif // _LIBINPUT_INPUT_EVENT_LABELS_H
458