blob: c6eef9becffb2ae70ffbf5aafbe656827d061be4 [file] [log] [blame]
Michael Wright872db4f2014-04-22 15:03:51 -07001/*
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
268 { NULL, 0 }
269};
270
271static const InputEventLabel AXES[] = {
272 DEFINE_AXIS(X),
273 DEFINE_AXIS(Y),
274 DEFINE_AXIS(PRESSURE),
275 DEFINE_AXIS(SIZE),
276 DEFINE_AXIS(TOUCH_MAJOR),
277 DEFINE_AXIS(TOUCH_MINOR),
278 DEFINE_AXIS(TOOL_MAJOR),
279 DEFINE_AXIS(TOOL_MINOR),
280 DEFINE_AXIS(ORIENTATION),
281 DEFINE_AXIS(VSCROLL),
282 DEFINE_AXIS(HSCROLL),
283 DEFINE_AXIS(Z),
284 DEFINE_AXIS(RX),
285 DEFINE_AXIS(RY),
286 DEFINE_AXIS(RZ),
287 DEFINE_AXIS(HAT_X),
288 DEFINE_AXIS(HAT_Y),
289 DEFINE_AXIS(LTRIGGER),
290 DEFINE_AXIS(RTRIGGER),
291 DEFINE_AXIS(THROTTLE),
292 DEFINE_AXIS(RUDDER),
293 DEFINE_AXIS(WHEEL),
294 DEFINE_AXIS(GAS),
295 DEFINE_AXIS(BRAKE),
296 DEFINE_AXIS(DISTANCE),
297 DEFINE_AXIS(TILT),
298 DEFINE_AXIS(GENERIC_1),
299 DEFINE_AXIS(GENERIC_2),
300 DEFINE_AXIS(GENERIC_3),
301 DEFINE_AXIS(GENERIC_4),
302 DEFINE_AXIS(GENERIC_5),
303 DEFINE_AXIS(GENERIC_6),
304 DEFINE_AXIS(GENERIC_7),
305 DEFINE_AXIS(GENERIC_8),
306 DEFINE_AXIS(GENERIC_9),
307 DEFINE_AXIS(GENERIC_10),
308 DEFINE_AXIS(GENERIC_11),
309 DEFINE_AXIS(GENERIC_12),
310 DEFINE_AXIS(GENERIC_13),
311 DEFINE_AXIS(GENERIC_14),
312 DEFINE_AXIS(GENERIC_15),
313 DEFINE_AXIS(GENERIC_16),
314
315 // NOTE: If you add a new axis here you must also add it to several other files.
316 // Refer to frameworks/base/core/java/android/view/MotionEvent.java for the full list.
317 { NULL, 0 }
318};
319
320static const InputEventLabel LEDS[] = {
321 DEFINE_LED(NUM_LOCK),
322 DEFINE_LED(CAPS_LOCK),
323 DEFINE_LED(SCROLL_LOCK),
324 DEFINE_LED(COMPOSE),
325 DEFINE_LED(KANA),
326 DEFINE_LED(SLEEP),
327 DEFINE_LED(SUSPEND),
328 DEFINE_LED(MUTE),
329 DEFINE_LED(MISC),
330 DEFINE_LED(MAIL),
331 DEFINE_LED(CHARGING),
332 DEFINE_LED(CONTROLLER_1),
333 DEFINE_LED(CONTROLLER_2),
334 DEFINE_LED(CONTROLLER_3),
335 DEFINE_LED(CONTROLLER_4),
336
337 // NOTE: If you add new LEDs here, you must also add them to Input.h
338 { NULL, 0 }
339};
340
341static const InputEventLabel FLAGS[] = {
342 DEFINE_FLAG(FUNCTION),
343
344 { NULL, 0 }
345};
346
347static int lookupValueByLabel(const char* literal, const InputEventLabel *list) {
348 while (list->literal) {
349 if (strcmp(literal, list->literal) == 0) {
350 return list->value;
351 }
352 list++;
353 }
354 return list->value;
355}
356
357static const char* lookupLabelByValue(int value, const InputEventLabel* list) {
358 while (list->literal) {
359 if (list->value == value) {
360 return list->literal;
361 }
362 list++;
363 }
364 return NULL;
365}
366
367static int32_t getKeyCodeByLabel(const char* label) {
368 return int32_t(lookupValueByLabel(label, KEYCODES));
369}
370
371static const char* getLabelByKeyCode(int32_t keyCode) {
372 if (keyCode >= 0 && keyCode < size(KEYCODES)) {
373 return KEYCODES[keyCode].literal;
374 }
375 return NULL;
376}
377
378static uint32_t getKeyFlagByLabel(const char* label) {
379 return uint32_t(lookupValueByLabel(label, FLAGS));
380}
381
382static int32_t getAxisByLabel(const char* label) {
383 return int32_t(lookupValueByLabel(label, AXES));
384}
385
386static const char* getAxisLabel(int32_t axisId) {
387 return lookupLabelByValue(axisId, AXES);
388}
389
390static int32_t getLedByLabel(const char* label) {
391 return int32_t(lookupValueByLabel(label, LEDS));
392}
393
394
395} // namespace android
396#endif // _LIBINPUT_INPUT_EVENT_LABELS_H