InputEventLabels.h 13 KB

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