key_mapping_xkb.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /**************************************************************************/
  2. /* key_mapping_xkb.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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. #include "key_mapping_xkb.h"
  31. void KeyMappingXKB::initialize() {
  32. // XKB keycode to Godot Key map.
  33. xkb_keycode_map[XKB_KEY_Escape] = Key::ESCAPE;
  34. xkb_keycode_map[XKB_KEY_Tab] = Key::TAB;
  35. xkb_keycode_map[XKB_KEY_ISO_Left_Tab] = Key::BACKTAB;
  36. xkb_keycode_map[XKB_KEY_BackSpace] = Key::BACKSPACE;
  37. xkb_keycode_map[XKB_KEY_Return] = Key::ENTER;
  38. xkb_keycode_map[XKB_KEY_Insert] = Key::INSERT;
  39. xkb_keycode_map[XKB_KEY_Delete] = Key::KEY_DELETE;
  40. xkb_keycode_map[XKB_KEY_Clear] = Key::KEY_DELETE;
  41. xkb_keycode_map[XKB_KEY_Pause] = Key::PAUSE;
  42. xkb_keycode_map[XKB_KEY_Print] = Key::PRINT;
  43. xkb_keycode_map[XKB_KEY_Home] = Key::HOME;
  44. xkb_keycode_map[XKB_KEY_End] = Key::END;
  45. xkb_keycode_map[XKB_KEY_Left] = Key::LEFT;
  46. xkb_keycode_map[XKB_KEY_Up] = Key::UP;
  47. xkb_keycode_map[XKB_KEY_Right] = Key::RIGHT;
  48. xkb_keycode_map[XKB_KEY_Down] = Key::DOWN;
  49. xkb_keycode_map[XKB_KEY_Prior] = Key::PAGEUP;
  50. xkb_keycode_map[XKB_KEY_Next] = Key::PAGEDOWN;
  51. xkb_keycode_map[XKB_KEY_Shift_L] = Key::SHIFT;
  52. xkb_keycode_map[XKB_KEY_Shift_R] = Key::SHIFT;
  53. xkb_keycode_map[XKB_KEY_Shift_Lock] = Key::SHIFT;
  54. xkb_keycode_map[XKB_KEY_Control_L] = Key::CTRL;
  55. xkb_keycode_map[XKB_KEY_Control_R] = Key::CTRL;
  56. xkb_keycode_map[XKB_KEY_Meta_L] = Key::META;
  57. xkb_keycode_map[XKB_KEY_Meta_R] = Key::META;
  58. xkb_keycode_map[XKB_KEY_Alt_L] = Key::ALT;
  59. xkb_keycode_map[XKB_KEY_Alt_R] = Key::ALT;
  60. xkb_keycode_map[XKB_KEY_Caps_Lock] = Key::CAPSLOCK;
  61. xkb_keycode_map[XKB_KEY_Num_Lock] = Key::NUMLOCK;
  62. xkb_keycode_map[XKB_KEY_Scroll_Lock] = Key::SCROLLLOCK;
  63. xkb_keycode_map[XKB_KEY_less] = Key::QUOTELEFT;
  64. xkb_keycode_map[XKB_KEY_grave] = Key::SECTION;
  65. xkb_keycode_map[XKB_KEY_Super_L] = Key::META;
  66. xkb_keycode_map[XKB_KEY_Super_R] = Key::META;
  67. xkb_keycode_map[XKB_KEY_Menu] = Key::MENU;
  68. xkb_keycode_map[XKB_KEY_Hyper_L] = Key::HYPER;
  69. xkb_keycode_map[XKB_KEY_Hyper_R] = Key::HYPER;
  70. xkb_keycode_map[XKB_KEY_Help] = Key::HELP;
  71. xkb_keycode_map[XKB_KEY_KP_Space] = Key::SPACE;
  72. xkb_keycode_map[XKB_KEY_KP_Tab] = Key::TAB;
  73. xkb_keycode_map[XKB_KEY_KP_Enter] = Key::KP_ENTER;
  74. xkb_keycode_map[XKB_KEY_Home] = Key::HOME;
  75. xkb_keycode_map[XKB_KEY_Left] = Key::LEFT;
  76. xkb_keycode_map[XKB_KEY_Up] = Key::UP;
  77. xkb_keycode_map[XKB_KEY_Right] = Key::RIGHT;
  78. xkb_keycode_map[XKB_KEY_Down] = Key::DOWN;
  79. xkb_keycode_map[XKB_KEY_Prior] = Key::PAGEUP;
  80. xkb_keycode_map[XKB_KEY_Next] = Key::PAGEDOWN;
  81. xkb_keycode_map[XKB_KEY_End] = Key::END;
  82. xkb_keycode_map[XKB_KEY_Begin] = Key::CLEAR;
  83. xkb_keycode_map[XKB_KEY_Insert] = Key::INSERT;
  84. xkb_keycode_map[XKB_KEY_Delete] = Key::KEY_DELETE;
  85. xkb_keycode_map[XKB_KEY_KP_Equal] = Key::EQUAL;
  86. xkb_keycode_map[XKB_KEY_KP_Separator] = Key::COMMA;
  87. xkb_keycode_map[XKB_KEY_KP_Decimal] = Key::KP_PERIOD;
  88. xkb_keycode_map[XKB_KEY_KP_Multiply] = Key::KP_MULTIPLY;
  89. xkb_keycode_map[XKB_KEY_KP_Divide] = Key::KP_DIVIDE;
  90. xkb_keycode_map[XKB_KEY_KP_Subtract] = Key::KP_SUBTRACT;
  91. xkb_keycode_map[XKB_KEY_KP_Add] = Key::KP_ADD;
  92. xkb_keycode_map[XKB_KEY_KP_0] = Key::KP_0;
  93. xkb_keycode_map[XKB_KEY_KP_1] = Key::KP_1;
  94. xkb_keycode_map[XKB_KEY_KP_2] = Key::KP_2;
  95. xkb_keycode_map[XKB_KEY_KP_3] = Key::KP_3;
  96. xkb_keycode_map[XKB_KEY_KP_4] = Key::KP_4;
  97. xkb_keycode_map[XKB_KEY_KP_5] = Key::KP_5;
  98. xkb_keycode_map[XKB_KEY_KP_6] = Key::KP_6;
  99. xkb_keycode_map[XKB_KEY_KP_7] = Key::KP_7;
  100. xkb_keycode_map[XKB_KEY_KP_8] = Key::KP_8;
  101. xkb_keycode_map[XKB_KEY_KP_9] = Key::KP_9;
  102. // Same keys but with numlock off.
  103. xkb_keycode_map[XKB_KEY_KP_Insert] = Key::INSERT;
  104. xkb_keycode_map[XKB_KEY_KP_Delete] = Key::KEY_DELETE;
  105. xkb_keycode_map[XKB_KEY_KP_End] = Key::END;
  106. xkb_keycode_map[XKB_KEY_KP_Down] = Key::DOWN;
  107. xkb_keycode_map[XKB_KEY_KP_Page_Down] = Key::PAGEDOWN;
  108. xkb_keycode_map[XKB_KEY_KP_Left] = Key::LEFT;
  109. // X11 documents this (numpad 5) as "begin of line" but no toolkit seems to interpret it this way.
  110. // On Windows this is emitting Key::Clear so for consistency it will be mapped to Key::Clear
  111. xkb_keycode_map[XKB_KEY_KP_Begin] = Key::CLEAR;
  112. xkb_keycode_map[XKB_KEY_KP_Right] = Key::RIGHT;
  113. xkb_keycode_map[XKB_KEY_KP_Home] = Key::HOME;
  114. xkb_keycode_map[XKB_KEY_KP_Up] = Key::UP;
  115. xkb_keycode_map[XKB_KEY_KP_Page_Up] = Key::PAGEUP;
  116. xkb_keycode_map[XKB_KEY_F1] = Key::F1;
  117. xkb_keycode_map[XKB_KEY_F2] = Key::F2;
  118. xkb_keycode_map[XKB_KEY_F3] = Key::F3;
  119. xkb_keycode_map[XKB_KEY_F4] = Key::F4;
  120. xkb_keycode_map[XKB_KEY_F5] = Key::F5;
  121. xkb_keycode_map[XKB_KEY_F6] = Key::F6;
  122. xkb_keycode_map[XKB_KEY_F7] = Key::F7;
  123. xkb_keycode_map[XKB_KEY_F8] = Key::F8;
  124. xkb_keycode_map[XKB_KEY_F9] = Key::F9;
  125. xkb_keycode_map[XKB_KEY_F10] = Key::F10;
  126. xkb_keycode_map[XKB_KEY_F11] = Key::F11;
  127. xkb_keycode_map[XKB_KEY_F12] = Key::F12;
  128. xkb_keycode_map[XKB_KEY_F13] = Key::F13;
  129. xkb_keycode_map[XKB_KEY_F14] = Key::F14;
  130. xkb_keycode_map[XKB_KEY_F15] = Key::F15;
  131. xkb_keycode_map[XKB_KEY_F16] = Key::F16;
  132. xkb_keycode_map[XKB_KEY_F17] = Key::F17;
  133. xkb_keycode_map[XKB_KEY_F18] = Key::F18;
  134. xkb_keycode_map[XKB_KEY_F19] = Key::F19;
  135. xkb_keycode_map[XKB_KEY_F20] = Key::F20;
  136. xkb_keycode_map[XKB_KEY_F21] = Key::F21;
  137. xkb_keycode_map[XKB_KEY_F22] = Key::F22;
  138. xkb_keycode_map[XKB_KEY_F23] = Key::F23;
  139. xkb_keycode_map[XKB_KEY_F24] = Key::F24;
  140. xkb_keycode_map[XKB_KEY_F25] = Key::F25;
  141. xkb_keycode_map[XKB_KEY_F26] = Key::F26;
  142. xkb_keycode_map[XKB_KEY_F27] = Key::F27;
  143. xkb_keycode_map[XKB_KEY_F28] = Key::F28;
  144. xkb_keycode_map[XKB_KEY_F29] = Key::F29;
  145. xkb_keycode_map[XKB_KEY_F30] = Key::F30;
  146. xkb_keycode_map[XKB_KEY_F31] = Key::F31;
  147. xkb_keycode_map[XKB_KEY_F32] = Key::F32;
  148. xkb_keycode_map[XKB_KEY_F33] = Key::F33;
  149. xkb_keycode_map[XKB_KEY_F34] = Key::F34;
  150. xkb_keycode_map[XKB_KEY_F35] = Key::F35;
  151. xkb_keycode_map[XKB_KEY_yen] = Key::YEN;
  152. xkb_keycode_map[XKB_KEY_section] = Key::SECTION;
  153. // Media keys.
  154. xkb_keycode_map[XKB_KEY_XF86Back] = Key::BACK;
  155. xkb_keycode_map[XKB_KEY_XF86Forward] = Key::FORWARD;
  156. xkb_keycode_map[XKB_KEY_XF86Stop] = Key::STOP;
  157. xkb_keycode_map[XKB_KEY_XF86Refresh] = Key::REFRESH;
  158. xkb_keycode_map[XKB_KEY_XF86Favorites] = Key::FAVORITES;
  159. xkb_keycode_map[XKB_KEY_XF86OpenURL] = Key::OPENURL;
  160. xkb_keycode_map[XKB_KEY_XF86HomePage] = Key::HOMEPAGE;
  161. xkb_keycode_map[XKB_KEY_XF86Search] = Key::SEARCH;
  162. xkb_keycode_map[XKB_KEY_XF86AudioLowerVolume] = Key::VOLUMEDOWN;
  163. xkb_keycode_map[XKB_KEY_XF86AudioMute] = Key::VOLUMEMUTE;
  164. xkb_keycode_map[XKB_KEY_XF86AudioRaiseVolume] = Key::VOLUMEUP;
  165. xkb_keycode_map[XKB_KEY_XF86AudioPlay] = Key::MEDIAPLAY;
  166. xkb_keycode_map[XKB_KEY_XF86AudioStop] = Key::MEDIASTOP;
  167. xkb_keycode_map[XKB_KEY_XF86AudioPrev] = Key::MEDIAPREVIOUS;
  168. xkb_keycode_map[XKB_KEY_XF86AudioNext] = Key::MEDIANEXT;
  169. xkb_keycode_map[XKB_KEY_XF86AudioRecord] = Key::MEDIARECORD;
  170. xkb_keycode_map[XKB_KEY_XF86Standby] = Key::STANDBY;
  171. // Launch keys.
  172. xkb_keycode_map[XKB_KEY_XF86Mail] = Key::LAUNCHMAIL;
  173. xkb_keycode_map[XKB_KEY_XF86AudioMedia] = Key::LAUNCHMEDIA;
  174. xkb_keycode_map[XKB_KEY_XF86MyComputer] = Key::LAUNCH0;
  175. xkb_keycode_map[XKB_KEY_XF86Calculator] = Key::LAUNCH1;
  176. xkb_keycode_map[XKB_KEY_XF86Launch0] = Key::LAUNCH2;
  177. xkb_keycode_map[XKB_KEY_XF86Launch1] = Key::LAUNCH3;
  178. xkb_keycode_map[XKB_KEY_XF86Launch2] = Key::LAUNCH4;
  179. xkb_keycode_map[XKB_KEY_XF86Launch3] = Key::LAUNCH5;
  180. xkb_keycode_map[XKB_KEY_XF86Launch4] = Key::LAUNCH6;
  181. xkb_keycode_map[XKB_KEY_XF86Launch5] = Key::LAUNCH7;
  182. xkb_keycode_map[XKB_KEY_XF86Launch6] = Key::LAUNCH8;
  183. xkb_keycode_map[XKB_KEY_XF86Launch7] = Key::LAUNCH9;
  184. xkb_keycode_map[XKB_KEY_XF86Launch8] = Key::LAUNCHA;
  185. xkb_keycode_map[XKB_KEY_XF86Launch9] = Key::LAUNCHB;
  186. xkb_keycode_map[XKB_KEY_XF86LaunchA] = Key::LAUNCHC;
  187. xkb_keycode_map[XKB_KEY_XF86LaunchB] = Key::LAUNCHD;
  188. xkb_keycode_map[XKB_KEY_XF86LaunchC] = Key::LAUNCHE;
  189. xkb_keycode_map[XKB_KEY_XF86LaunchD] = Key::LAUNCHF;
  190. // Scancode to Godot Key map.
  191. scancode_map[0x09] = Key::ESCAPE;
  192. scancode_map[0x0A] = Key::KEY_1;
  193. scancode_map[0x0B] = Key::KEY_2;
  194. scancode_map[0x0C] = Key::KEY_3;
  195. scancode_map[0x0D] = Key::KEY_4;
  196. scancode_map[0x0E] = Key::KEY_5;
  197. scancode_map[0x0F] = Key::KEY_6;
  198. scancode_map[0x10] = Key::KEY_7;
  199. scancode_map[0x11] = Key::KEY_8;
  200. scancode_map[0x12] = Key::KEY_9;
  201. scancode_map[0x13] = Key::KEY_0;
  202. scancode_map[0x14] = Key::MINUS;
  203. scancode_map[0x15] = Key::EQUAL;
  204. scancode_map[0x16] = Key::BACKSPACE;
  205. scancode_map[0x17] = Key::TAB;
  206. scancode_map[0x18] = Key::Q;
  207. scancode_map[0x19] = Key::W;
  208. scancode_map[0x1A] = Key::E;
  209. scancode_map[0x1B] = Key::R;
  210. scancode_map[0x1C] = Key::T;
  211. scancode_map[0x1D] = Key::Y;
  212. scancode_map[0x1E] = Key::U;
  213. scancode_map[0x1F] = Key::I;
  214. scancode_map[0x20] = Key::O;
  215. scancode_map[0x21] = Key::P;
  216. scancode_map[0x22] = Key::BRACELEFT;
  217. scancode_map[0x23] = Key::BRACERIGHT;
  218. scancode_map[0x24] = Key::ENTER;
  219. scancode_map[0x25] = Key::CTRL; // Left
  220. scancode_map[0x26] = Key::A;
  221. scancode_map[0x27] = Key::S;
  222. scancode_map[0x28] = Key::D;
  223. scancode_map[0x29] = Key::F;
  224. scancode_map[0x2A] = Key::G;
  225. scancode_map[0x2B] = Key::H;
  226. scancode_map[0x2C] = Key::J;
  227. scancode_map[0x2D] = Key::K;
  228. scancode_map[0x2E] = Key::L;
  229. scancode_map[0x2F] = Key::SEMICOLON;
  230. scancode_map[0x30] = Key::APOSTROPHE;
  231. scancode_map[0x31] = Key::SECTION;
  232. scancode_map[0x32] = Key::SHIFT; // Left
  233. scancode_map[0x33] = Key::BACKSLASH;
  234. scancode_map[0x34] = Key::Z;
  235. scancode_map[0x35] = Key::X;
  236. scancode_map[0x36] = Key::C;
  237. scancode_map[0x37] = Key::V;
  238. scancode_map[0x38] = Key::B;
  239. scancode_map[0x39] = Key::N;
  240. scancode_map[0x3A] = Key::M;
  241. scancode_map[0x3B] = Key::COMMA;
  242. scancode_map[0x3C] = Key::PERIOD;
  243. scancode_map[0x3D] = Key::SLASH;
  244. scancode_map[0x3E] = Key::SHIFT; // Right
  245. scancode_map[0x3F] = Key::KP_MULTIPLY;
  246. scancode_map[0x40] = Key::ALT; // Left
  247. scancode_map[0x41] = Key::SPACE;
  248. scancode_map[0x42] = Key::CAPSLOCK;
  249. scancode_map[0x43] = Key::F1;
  250. scancode_map[0x44] = Key::F2;
  251. scancode_map[0x45] = Key::F3;
  252. scancode_map[0x46] = Key::F4;
  253. scancode_map[0x47] = Key::F5;
  254. scancode_map[0x48] = Key::F6;
  255. scancode_map[0x49] = Key::F7;
  256. scancode_map[0x4A] = Key::F8;
  257. scancode_map[0x4B] = Key::F9;
  258. scancode_map[0x4C] = Key::F10;
  259. scancode_map[0x4D] = Key::NUMLOCK;
  260. scancode_map[0x4E] = Key::SCROLLLOCK;
  261. scancode_map[0x4F] = Key::KP_7;
  262. scancode_map[0x50] = Key::KP_8;
  263. scancode_map[0x51] = Key::KP_9;
  264. scancode_map[0x52] = Key::KP_SUBTRACT;
  265. scancode_map[0x53] = Key::KP_4;
  266. scancode_map[0x54] = Key::KP_5;
  267. scancode_map[0x55] = Key::KP_6;
  268. scancode_map[0x56] = Key::KP_ADD;
  269. scancode_map[0x57] = Key::KP_1;
  270. scancode_map[0x58] = Key::KP_2;
  271. scancode_map[0x59] = Key::KP_3;
  272. scancode_map[0x5A] = Key::KP_0;
  273. scancode_map[0x5B] = Key::KP_PERIOD;
  274. //scancode_map[0x5C]
  275. //scancode_map[0x5D] // Zenkaku Hankaku
  276. scancode_map[0x5E] = Key::QUOTELEFT;
  277. scancode_map[0x5F] = Key::F11;
  278. scancode_map[0x60] = Key::F12;
  279. //scancode_map[0x61] // Romaji
  280. //scancode_map[0x62] // Katakana
  281. //scancode_map[0x63] // Hiragana
  282. //scancode_map[0x64] // Henkan
  283. //scancode_map[0x65] // Hiragana Katakana
  284. //scancode_map[0x66] // Muhenkan
  285. scancode_map[0x67] = Key::COMMA; // KP_Separator
  286. scancode_map[0x68] = Key::KP_ENTER;
  287. scancode_map[0x69] = Key::CTRL; // Right
  288. scancode_map[0x6A] = Key::KP_DIVIDE;
  289. scancode_map[0x6B] = Key::PRINT;
  290. scancode_map[0x6C] = Key::ALT; // Right
  291. scancode_map[0x6D] = Key::ENTER;
  292. scancode_map[0x6E] = Key::HOME;
  293. scancode_map[0x6F] = Key::UP;
  294. scancode_map[0x70] = Key::PAGEUP;
  295. scancode_map[0x71] = Key::LEFT;
  296. scancode_map[0x72] = Key::RIGHT;
  297. scancode_map[0x73] = Key::END;
  298. scancode_map[0x74] = Key::DOWN;
  299. scancode_map[0x75] = Key::PAGEDOWN;
  300. scancode_map[0x76] = Key::INSERT;
  301. scancode_map[0x77] = Key::KEY_DELETE;
  302. //scancode_map[0x78] // Macro
  303. scancode_map[0x79] = Key::VOLUMEMUTE;
  304. scancode_map[0x7A] = Key::VOLUMEDOWN;
  305. scancode_map[0x7B] = Key::VOLUMEUP;
  306. //scancode_map[0x7C] // Power
  307. scancode_map[0x7D] = Key::EQUAL; // KP_Equal
  308. //scancode_map[0x7E] // KP_PlusMinus
  309. scancode_map[0x7F] = Key::PAUSE;
  310. scancode_map[0x80] = Key::LAUNCH0;
  311. scancode_map[0x81] = Key::COMMA; // KP_Comma
  312. //scancode_map[0x82] // Hangul
  313. //scancode_map[0x83] // Hangul_Hanja
  314. scancode_map[0x84] = Key::YEN;
  315. scancode_map[0x85] = Key::META; // Left
  316. scancode_map[0x86] = Key::META; // Right
  317. scancode_map[0x87] = Key::MENU;
  318. scancode_map[0xA6] = Key::BACK; // On Chromebooks
  319. scancode_map[0xA7] = Key::FORWARD; // On Chromebooks
  320. scancode_map[0xB5] = Key::REFRESH; // On Chromebooks
  321. scancode_map[0xBF] = Key::F13;
  322. scancode_map[0xC0] = Key::F14;
  323. scancode_map[0xC1] = Key::F15;
  324. scancode_map[0xC2] = Key::F16;
  325. scancode_map[0xC3] = Key::F17;
  326. scancode_map[0xC4] = Key::F18;
  327. scancode_map[0xC5] = Key::F19;
  328. scancode_map[0xC6] = Key::F20;
  329. scancode_map[0xC7] = Key::F21;
  330. scancode_map[0xC8] = Key::F22;
  331. scancode_map[0xC9] = Key::F23;
  332. scancode_map[0xCA] = Key::F24;
  333. scancode_map[0xCB] = Key::F25;
  334. scancode_map[0xCC] = Key::F26;
  335. scancode_map[0xCD] = Key::F27;
  336. scancode_map[0xCE] = Key::F28;
  337. scancode_map[0xCF] = Key::F29;
  338. scancode_map[0xD0] = Key::F30;
  339. scancode_map[0xD1] = Key::F31;
  340. scancode_map[0xD2] = Key::F32;
  341. scancode_map[0xD3] = Key::F33;
  342. scancode_map[0xD4] = Key::F34;
  343. scancode_map[0xD5] = Key::F35;
  344. // Godot to scancode map.
  345. for (const KeyValue<unsigned int, Key> &E : scancode_map) {
  346. scancode_map_inv[E.value] = E.key;
  347. }
  348. // Scancode to physical location map.
  349. // Ctrl.
  350. location_map[0x25] = KeyLocation::LEFT;
  351. location_map[0x69] = KeyLocation::RIGHT;
  352. // Shift.
  353. location_map[0x32] = KeyLocation::LEFT;
  354. location_map[0x3E] = KeyLocation::RIGHT;
  355. // Alt.
  356. location_map[0x40] = KeyLocation::LEFT;
  357. location_map[0x6C] = KeyLocation::RIGHT;
  358. // Meta.
  359. location_map[0x85] = KeyLocation::LEFT;
  360. location_map[0x86] = KeyLocation::RIGHT;
  361. }
  362. Key KeyMappingXKB::get_keycode(xkb_keycode_t p_keysym) {
  363. if (p_keysym >= 0x20 && p_keysym < 0x7E) { // ASCII, maps 1-1
  364. if (p_keysym > 0x60 && p_keysym < 0x7B) { // Lowercase ASCII.
  365. return (Key)(p_keysym - 32);
  366. } else {
  367. return (Key)p_keysym;
  368. }
  369. }
  370. const Key *key = xkb_keycode_map.getptr(p_keysym);
  371. if (key) {
  372. return *key;
  373. }
  374. return Key::NONE;
  375. }
  376. Key KeyMappingXKB::get_scancode(unsigned int p_code) {
  377. const Key *key = scancode_map.getptr(p_code);
  378. if (key) {
  379. return *key;
  380. }
  381. return Key::NONE;
  382. }
  383. xkb_keycode_t KeyMappingXKB::get_xkb_keycode(Key p_key) {
  384. const unsigned int *key = scancode_map_inv.getptr(p_key);
  385. if (key) {
  386. return *key;
  387. }
  388. return 0x00;
  389. }
  390. KeyLocation KeyMappingXKB::get_location(unsigned int p_code) {
  391. const KeyLocation *location = location_map.getptr(p_code);
  392. if (location) {
  393. return *location;
  394. }
  395. return KeyLocation::UNSPECIFIED;
  396. }