android_keys_utils.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*************************************************************************/
  2. /* android_keys_utils.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #ifndef ANDROID_KEYS_UTILS_H
  31. #define ANDROID_KEYS_UTILS_H
  32. #include <core/os/keyboard.h>
  33. /*
  34. * Android Key codes.
  35. */
  36. enum {
  37. AKEYCODE_UNKNOWN = 0,
  38. AKEYCODE_SOFT_LEFT = 1,
  39. AKEYCODE_SOFT_RIGHT = 2,
  40. AKEYCODE_HOME = 3,
  41. AKEYCODE_BACK = 4,
  42. AKEYCODE_CALL = 5,
  43. AKEYCODE_ENDCALL = 6,
  44. AKEYCODE_0 = 7,
  45. AKEYCODE_1 = 8,
  46. AKEYCODE_2 = 9,
  47. AKEYCODE_3 = 10,
  48. AKEYCODE_4 = 11,
  49. AKEYCODE_5 = 12,
  50. AKEYCODE_6 = 13,
  51. AKEYCODE_7 = 14,
  52. AKEYCODE_8 = 15,
  53. AKEYCODE_9 = 16,
  54. AKEYCODE_STAR = 17,
  55. AKEYCODE_POUND = 18,
  56. AKEYCODE_DPAD_UP = 19,
  57. AKEYCODE_DPAD_DOWN = 20,
  58. AKEYCODE_DPAD_LEFT = 21,
  59. AKEYCODE_DPAD_RIGHT = 22,
  60. AKEYCODE_DPAD_CENTER = 23,
  61. AKEYCODE_VOLUME_UP = 24,
  62. AKEYCODE_VOLUME_DOWN = 25,
  63. AKEYCODE_POWER = 26,
  64. AKEYCODE_CAMERA = 27,
  65. AKEYCODE_CLEAR = 28,
  66. AKEYCODE_A = 29,
  67. AKEYCODE_B = 30,
  68. AKEYCODE_C = 31,
  69. AKEYCODE_D = 32,
  70. AKEYCODE_E = 33,
  71. AKEYCODE_F = 34,
  72. AKEYCODE_G = 35,
  73. AKEYCODE_H = 36,
  74. AKEYCODE_I = 37,
  75. AKEYCODE_J = 38,
  76. AKEYCODE_K = 39,
  77. AKEYCODE_L = 40,
  78. AKEYCODE_M = 41,
  79. AKEYCODE_N = 42,
  80. AKEYCODE_O = 43,
  81. AKEYCODE_P = 44,
  82. AKEYCODE_Q = 45,
  83. AKEYCODE_R = 46,
  84. AKEYCODE_S = 47,
  85. AKEYCODE_T = 48,
  86. AKEYCODE_U = 49,
  87. AKEYCODE_V = 50,
  88. AKEYCODE_W = 51,
  89. AKEYCODE_X = 52,
  90. AKEYCODE_Y = 53,
  91. AKEYCODE_Z = 54,
  92. AKEYCODE_COMMA = 55,
  93. AKEYCODE_PERIOD = 56,
  94. AKEYCODE_ALT_LEFT = 57,
  95. AKEYCODE_ALT_RIGHT = 58,
  96. AKEYCODE_SHIFT_LEFT = 59,
  97. AKEYCODE_SHIFT_RIGHT = 60,
  98. AKEYCODE_TAB = 61,
  99. AKEYCODE_SPACE = 62,
  100. AKEYCODE_SYM = 63,
  101. AKEYCODE_EXPLORER = 64,
  102. AKEYCODE_ENVELOPE = 65,
  103. AKEYCODE_ENTER = 66,
  104. AKEYCODE_DEL = 67,
  105. AKEYCODE_GRAVE = 68,
  106. AKEYCODE_MINUS = 69,
  107. AKEYCODE_EQUALS = 70,
  108. AKEYCODE_LEFT_BRACKET = 71,
  109. AKEYCODE_RIGHT_BRACKET = 72,
  110. AKEYCODE_BACKSLASH = 73,
  111. AKEYCODE_SEMICOLON = 74,
  112. AKEYCODE_APOSTROPHE = 75,
  113. AKEYCODE_SLASH = 76,
  114. AKEYCODE_AT = 77,
  115. AKEYCODE_NUM = 78,
  116. AKEYCODE_HEADSETHOOK = 79,
  117. AKEYCODE_FOCUS = 80, // *Camera* focus
  118. AKEYCODE_PLUS = 81,
  119. AKEYCODE_MENU = 82,
  120. AKEYCODE_NOTIFICATION = 83,
  121. AKEYCODE_SEARCH = 84,
  122. AKEYCODE_MEDIA_PLAY_PAUSE = 85,
  123. AKEYCODE_MEDIA_STOP = 86,
  124. AKEYCODE_MEDIA_NEXT = 87,
  125. AKEYCODE_MEDIA_PREVIOUS = 88,
  126. AKEYCODE_MEDIA_REWIND = 89,
  127. AKEYCODE_MEDIA_FAST_FORWARD = 90,
  128. AKEYCODE_MUTE = 91,
  129. AKEYCODE_PAGE_UP = 92,
  130. AKEYCODE_PAGE_DOWN = 93,
  131. AKEYCODE_PICTSYMBOLS = 94,
  132. AKEYCODE_SWITCH_CHARSET = 95,
  133. AKEYCODE_BUTTON_A = 96,
  134. AKEYCODE_BUTTON_B = 97,
  135. AKEYCODE_BUTTON_C = 98,
  136. AKEYCODE_BUTTON_X = 99,
  137. AKEYCODE_BUTTON_Y = 100,
  138. AKEYCODE_BUTTON_Z = 101,
  139. AKEYCODE_BUTTON_L1 = 102,
  140. AKEYCODE_BUTTON_R1 = 103,
  141. AKEYCODE_BUTTON_L2 = 104,
  142. AKEYCODE_BUTTON_R2 = 105,
  143. AKEYCODE_BUTTON_THUMBL = 106,
  144. AKEYCODE_BUTTON_THUMBR = 107,
  145. AKEYCODE_BUTTON_START = 108,
  146. AKEYCODE_BUTTON_SELECT = 109,
  147. AKEYCODE_BUTTON_MODE = 110,
  148. // NOTE: If you add a new keycode here you must also add it to several other files.
  149. // Refer to frameworks/base/core/java/android/view/KeyEvent.java for the full list.
  150. };
  151. struct _WinTranslatePair {
  152. unsigned int keysym;
  153. unsigned int keycode;
  154. };
  155. static _WinTranslatePair _ak_to_keycode[] = {
  156. { KEY_TAB, AKEYCODE_TAB },
  157. { KEY_ENTER, AKEYCODE_ENTER },
  158. { KEY_SHIFT, AKEYCODE_SHIFT_LEFT },
  159. { KEY_SHIFT, AKEYCODE_SHIFT_RIGHT },
  160. { KEY_ALT, AKEYCODE_ALT_LEFT },
  161. { KEY_ALT, AKEYCODE_ALT_RIGHT },
  162. { KEY_MENU, AKEYCODE_MENU },
  163. { KEY_PAUSE, AKEYCODE_MEDIA_PLAY_PAUSE },
  164. { KEY_ESCAPE, AKEYCODE_BACK },
  165. { KEY_SPACE, AKEYCODE_SPACE },
  166. { KEY_PAGEUP, AKEYCODE_PAGE_UP },
  167. { KEY_PAGEDOWN, AKEYCODE_PAGE_DOWN },
  168. { KEY_HOME, AKEYCODE_HOME }, //(0x24)
  169. { KEY_LEFT, AKEYCODE_DPAD_LEFT },
  170. { KEY_UP, AKEYCODE_DPAD_UP },
  171. { KEY_RIGHT, AKEYCODE_DPAD_RIGHT },
  172. { KEY_DOWN, AKEYCODE_DPAD_DOWN },
  173. { KEY_PERIODCENTERED, AKEYCODE_DPAD_CENTER },
  174. { KEY_BACKSPACE, AKEYCODE_DEL },
  175. { KEY_0, AKEYCODE_0 }, ////0 key
  176. { KEY_1, AKEYCODE_1 }, ////1 key
  177. { KEY_2, AKEYCODE_2 }, ////2 key
  178. { KEY_3, AKEYCODE_3 }, ////3 key
  179. { KEY_4, AKEYCODE_4 }, ////4 key
  180. { KEY_5, AKEYCODE_5 }, ////5 key
  181. { KEY_6, AKEYCODE_6 }, ////6 key
  182. { KEY_7, AKEYCODE_7 }, ////7 key
  183. { KEY_8, AKEYCODE_8 }, ////8 key
  184. { KEY_9, AKEYCODE_9 }, ////9 key
  185. { KEY_A, AKEYCODE_A }, ////A key
  186. { KEY_B, AKEYCODE_B }, ////B key
  187. { KEY_C, AKEYCODE_C }, ////C key
  188. { KEY_D, AKEYCODE_D }, ////D key
  189. { KEY_E, AKEYCODE_E }, ////E key
  190. { KEY_F, AKEYCODE_F }, ////F key
  191. { KEY_G, AKEYCODE_G }, ////G key
  192. { KEY_H, AKEYCODE_H }, ////H key
  193. { KEY_I, AKEYCODE_I }, ////I key
  194. { KEY_J, AKEYCODE_J }, ////J key
  195. { KEY_K, AKEYCODE_K }, ////K key
  196. { KEY_L, AKEYCODE_L }, ////L key
  197. { KEY_M, AKEYCODE_M }, ////M key
  198. { KEY_N, AKEYCODE_N }, ////N key
  199. { KEY_O, AKEYCODE_O }, ////O key
  200. { KEY_P, AKEYCODE_P }, ////P key
  201. { KEY_Q, AKEYCODE_Q }, ////Q key
  202. { KEY_R, AKEYCODE_R }, ////R key
  203. { KEY_S, AKEYCODE_S }, ////S key
  204. { KEY_T, AKEYCODE_T }, ////T key
  205. { KEY_U, AKEYCODE_U }, ////U key
  206. { KEY_V, AKEYCODE_V }, ////V key
  207. { KEY_W, AKEYCODE_W }, ////W key
  208. { KEY_X, AKEYCODE_X }, ////X key
  209. { KEY_Y, AKEYCODE_Y }, ////Y key
  210. { KEY_Z, AKEYCODE_Z }, ////Z key
  211. { KEY_HOMEPAGE, AKEYCODE_EXPLORER },
  212. { KEY_LAUNCH0, AKEYCODE_BUTTON_A },
  213. { KEY_LAUNCH1, AKEYCODE_BUTTON_B },
  214. { KEY_LAUNCH2, AKEYCODE_BUTTON_C },
  215. { KEY_LAUNCH3, AKEYCODE_BUTTON_X },
  216. { KEY_LAUNCH4, AKEYCODE_BUTTON_Y },
  217. { KEY_LAUNCH5, AKEYCODE_BUTTON_Z },
  218. { KEY_LAUNCH6, AKEYCODE_BUTTON_L1 },
  219. { KEY_LAUNCH7, AKEYCODE_BUTTON_R1 },
  220. { KEY_LAUNCH8, AKEYCODE_BUTTON_L2 },
  221. { KEY_LAUNCH9, AKEYCODE_BUTTON_R2 },
  222. { KEY_LAUNCHA, AKEYCODE_BUTTON_THUMBL },
  223. { KEY_LAUNCHB, AKEYCODE_BUTTON_THUMBR },
  224. { KEY_LAUNCHC, AKEYCODE_BUTTON_START },
  225. { KEY_LAUNCHD, AKEYCODE_BUTTON_SELECT },
  226. { KEY_LAUNCHE, AKEYCODE_BUTTON_MODE },
  227. { KEY_VOLUMEMUTE, AKEYCODE_MUTE },
  228. { KEY_VOLUMEDOWN, AKEYCODE_VOLUME_DOWN },
  229. { KEY_VOLUMEUP, AKEYCODE_VOLUME_UP },
  230. { KEY_BACK, AKEYCODE_MEDIA_REWIND },
  231. { KEY_FORWARD, AKEYCODE_MEDIA_FAST_FORWARD },
  232. { KEY_MEDIANEXT, AKEYCODE_MEDIA_NEXT },
  233. { KEY_MEDIAPREVIOUS, AKEYCODE_MEDIA_PREVIOUS },
  234. { KEY_MEDIASTOP, AKEYCODE_MEDIA_STOP },
  235. { KEY_PLUS, AKEYCODE_PLUS },
  236. { KEY_EQUAL, AKEYCODE_EQUALS }, // the '+' key
  237. { KEY_COMMA, AKEYCODE_COMMA }, // the ',' key
  238. { KEY_MINUS, AKEYCODE_MINUS }, // the '-' key
  239. { KEY_SLASH, AKEYCODE_SLASH }, // the '/?' key
  240. { KEY_BACKSLASH, AKEYCODE_BACKSLASH },
  241. { KEY_BRACKETLEFT, AKEYCODE_LEFT_BRACKET },
  242. { KEY_BRACKETRIGHT, AKEYCODE_RIGHT_BRACKET },
  243. { KEY_UNKNOWN, 0 }
  244. };
  245. /*
  246. TODO: map these android key:
  247. AKEYCODE_SOFT_LEFT = 1,
  248. AKEYCODE_SOFT_RIGHT = 2,
  249. AKEYCODE_CALL = 5,
  250. AKEYCODE_ENDCALL = 6,
  251. AKEYCODE_STAR = 17,
  252. AKEYCODE_POUND = 18,
  253. AKEYCODE_POWER = 26,
  254. AKEYCODE_CAMERA = 27,
  255. AKEYCODE_CLEAR = 28,
  256. AKEYCODE_SYM = 63,
  257. AKEYCODE_ENVELOPE = 65,
  258. AKEYCODE_GRAVE = 68,
  259. AKEYCODE_SEMICOLON = 74,
  260. AKEYCODE_APOSTROPHE = 75,
  261. AKEYCODE_AT = 77,
  262. AKEYCODE_NUM = 78,
  263. AKEYCODE_HEADSETHOOK = 79,
  264. AKEYCODE_FOCUS = 80, // *Camera* focus
  265. AKEYCODE_NOTIFICATION = 83,
  266. AKEYCODE_SEARCH = 84,
  267. AKEYCODE_PICTSYMBOLS = 94,
  268. AKEYCODE_SWITCH_CHARSET = 95,
  269. */
  270. unsigned int android_get_keysym(unsigned int p_code);
  271. #endif // ANDROID_KEYS_UTILS_H