keyboard.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*************************************************************************/
  2. /* keyboard.cpp */
  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. #include "keyboard.h"
  31. #include "os/os.h"
  32. struct _KeyCodeText {
  33. int code;
  34. const char *text;
  35. };
  36. static const _KeyCodeText _keycodes[] = {
  37. /* clang-format off */
  38. {KEY_ESCAPE ,"Escape"},
  39. {KEY_TAB ,"Tab"},
  40. {KEY_BACKTAB ,"BackTab"},
  41. {KEY_BACKSPACE ,"BackSpace"},
  42. {KEY_RETURN ,"Return"},
  43. {KEY_ENTER ,"Enter"},
  44. {KEY_INSERT ,"Insert"},
  45. {KEY_DELETE ,"Delete"},
  46. {KEY_PAUSE ,"Pause"},
  47. {KEY_PRINT ,"Print"},
  48. {KEY_SYSREQ ,"SysReq"},
  49. {KEY_CLEAR ,"Clear"},
  50. {KEY_HOME ,"Home"},
  51. {KEY_END ,"End"},
  52. {KEY_LEFT ,"Left"},
  53. {KEY_UP ,"Up"},
  54. {KEY_RIGHT ,"Right"},
  55. {KEY_DOWN ,"Down"},
  56. {KEY_PAGEUP ,"PageUp"},
  57. {KEY_PAGEDOWN ,"PageDown"},
  58. {KEY_SHIFT ,"Shift"},
  59. {KEY_CONTROL ,"Control"},
  60. {KEY_META ,"Meta"},
  61. {KEY_ALT ,"Alt"},
  62. {KEY_CAPSLOCK ,"CapsLock"},
  63. {KEY_NUMLOCK ,"NumLock"},
  64. {KEY_SCROLLLOCK ,"ScrollLock"},
  65. {KEY_F1 ,"F1"},
  66. {KEY_F2 ,"F2"},
  67. {KEY_F3 ,"F3"},
  68. {KEY_F4 ,"F4"},
  69. {KEY_F5 ,"F5"},
  70. {KEY_F6 ,"F6"},
  71. {KEY_F7 ,"F7"},
  72. {KEY_F8 ,"F8"},
  73. {KEY_F9 ,"F9"},
  74. {KEY_F10 ,"F10"},
  75. {KEY_F11 ,"F11"},
  76. {KEY_F12 ,"F12"},
  77. {KEY_F13 ,"F13"},
  78. {KEY_F14 ,"F14"},
  79. {KEY_F15 ,"F15"},
  80. {KEY_F16 ,"F16"},
  81. {KEY_KP_ENTER ,"Kp Enter"},
  82. {KEY_KP_MULTIPLY ,"Kp Multiply"},
  83. {KEY_KP_DIVIDE ,"Kp Divide"},
  84. {KEY_KP_SUBTRACT ,"Kp Subtract"},
  85. {KEY_KP_PERIOD ,"Kp Period"},
  86. {KEY_KP_ADD ,"Kp Add"},
  87. {KEY_KP_0 ,"Kp 0"},
  88. {KEY_KP_1 ,"Kp 1"},
  89. {KEY_KP_2 ,"Kp 2"},
  90. {KEY_KP_3 ,"Kp 3"},
  91. {KEY_KP_4 ,"Kp 4"},
  92. {KEY_KP_5 ,"Kp 5"},
  93. {KEY_KP_6 ,"Kp 6"},
  94. {KEY_KP_7 ,"Kp 7"},
  95. {KEY_KP_8 ,"Kp 8"},
  96. {KEY_KP_9 ,"Kp 9"},
  97. {KEY_SUPER_L ,"Super L"},
  98. {KEY_SUPER_R ,"Super R"},
  99. {KEY_MENU ,"Menu"},
  100. {KEY_HYPER_L ,"Hyper L"},
  101. {KEY_HYPER_R ,"Hyper R"},
  102. {KEY_HELP ,"Help"},
  103. {KEY_DIRECTION_L ,"Direction L"},
  104. {KEY_DIRECTION_R ,"Direction R"},
  105. {KEY_BACK ,"Back"},
  106. {KEY_FORWARD ,"Forward"},
  107. {KEY_STOP ,"Stop"},
  108. {KEY_REFRESH ,"Refresh"},
  109. {KEY_VOLUMEDOWN ,"VolumeDown"},
  110. {KEY_VOLUMEMUTE ,"VolumeMute"},
  111. {KEY_VOLUMEUP ,"VolumeUp"},
  112. {KEY_BASSBOOST ,"BassBoost"},
  113. {KEY_BASSUP ,"BassUp"},
  114. {KEY_BASSDOWN ,"BassDown"},
  115. {KEY_TREBLEUP ,"TrebleUp"},
  116. {KEY_TREBLEDOWN ,"TrebleDown"},
  117. {KEY_MEDIAPLAY ,"MediaPlay"},
  118. {KEY_MEDIASTOP ,"MediaStop"},
  119. {KEY_MEDIAPREVIOUS ,"MediaPrevious"},
  120. {KEY_MEDIANEXT ,"MediaNext"},
  121. {KEY_MEDIARECORD ,"MediaRecord"},
  122. {KEY_HOMEPAGE ,"HomePage"},
  123. {KEY_FAVORITES ,"Favorites"},
  124. {KEY_SEARCH ,"Search"},
  125. {KEY_STANDBY ,"StandBy"},
  126. {KEY_LAUNCHMAIL ,"LaunchMail"},
  127. {KEY_LAUNCHMEDIA ,"LaunchMedia"},
  128. {KEY_LAUNCH0 ,"Launch0"},
  129. {KEY_LAUNCH1 ,"Launch1"},
  130. {KEY_LAUNCH2 ,"Launch2"},
  131. {KEY_LAUNCH3 ,"Launch3"},
  132. {KEY_LAUNCH4 ,"Launch4"},
  133. {KEY_LAUNCH5 ,"Launch5"},
  134. {KEY_LAUNCH6 ,"Launch6"},
  135. {KEY_LAUNCH7 ,"Launch7"},
  136. {KEY_LAUNCH8 ,"Launch8"},
  137. {KEY_LAUNCH9 ,"Launch9"},
  138. {KEY_LAUNCHA ,"LaunchA"},
  139. {KEY_LAUNCHB ,"LaunchB"},
  140. {KEY_LAUNCHC ,"LaunchC"},
  141. {KEY_LAUNCHD ,"LaunchD"},
  142. {KEY_LAUNCHE ,"LaunchE"},
  143. {KEY_LAUNCHF ,"LaunchF"},
  144. {KEY_UNKNOWN ,"Unknown"},
  145. {KEY_SPACE ,"Space"},
  146. {KEY_EXCLAM ,"Exclam"},
  147. {KEY_QUOTEDBL ,"QuoteDbl"},
  148. {KEY_NUMBERSIGN ,"NumberSign"},
  149. {KEY_DOLLAR ,"Dollar"},
  150. {KEY_PERCENT ,"Percent"},
  151. {KEY_AMPERSAND ,"Ampersand"},
  152. {KEY_APOSTROPHE ,"Apostrophe"},
  153. {KEY_PARENLEFT ,"ParenLeft"},
  154. {KEY_PARENRIGHT ,"ParenRight"},
  155. {KEY_ASTERISK ,"Asterisk"},
  156. {KEY_PLUS ,"Plus"},
  157. {KEY_COMMA ,"Comma"},
  158. {KEY_MINUS ,"Minus"},
  159. {KEY_PERIOD ,"Period"},
  160. {KEY_SLASH ,"Slash"},
  161. {KEY_0 ,"0"},
  162. {KEY_1 ,"1"},
  163. {KEY_2 ,"2"},
  164. {KEY_3 ,"3"},
  165. {KEY_4 ,"4"},
  166. {KEY_5 ,"5"},
  167. {KEY_6 ,"6"},
  168. {KEY_7 ,"7"},
  169. {KEY_8 ,"8"},
  170. {KEY_9 ,"9"},
  171. {KEY_COLON ,"Colon"},
  172. {KEY_SEMICOLON ,"Semicolon"},
  173. {KEY_LESS ,"Less"},
  174. {KEY_EQUAL ,"Equal"},
  175. {KEY_GREATER ,"Greater"},
  176. {KEY_QUESTION ,"Question"},
  177. {KEY_AT ,"At"},
  178. {KEY_A ,"A"},
  179. {KEY_B ,"B"},
  180. {KEY_C ,"C"},
  181. {KEY_D ,"D"},
  182. {KEY_E ,"E"},
  183. {KEY_F ,"F"},
  184. {KEY_G ,"G"},
  185. {KEY_H ,"H"},
  186. {KEY_I ,"I"},
  187. {KEY_J ,"J"},
  188. {KEY_K ,"K"},
  189. {KEY_L ,"L"},
  190. {KEY_M ,"M"},
  191. {KEY_N ,"N"},
  192. {KEY_O ,"O"},
  193. {KEY_P ,"P"},
  194. {KEY_Q ,"Q"},
  195. {KEY_R ,"R"},
  196. {KEY_S ,"S"},
  197. {KEY_T ,"T"},
  198. {KEY_U ,"U"},
  199. {KEY_V ,"V"},
  200. {KEY_W ,"W"},
  201. {KEY_X ,"X"},
  202. {KEY_Y ,"Y"},
  203. {KEY_Z ,"Z"},
  204. {KEY_BRACKETLEFT ,"BracketLeft"},
  205. {KEY_BACKSLASH ,"BackSlash"},
  206. {KEY_BRACKETRIGHT ,"BracketRight"},
  207. {KEY_ASCIICIRCUM ,"AsciiCircum"},
  208. {KEY_UNDERSCORE ,"UnderScore"},
  209. {KEY_QUOTELEFT ,"QuoteLeft"},
  210. {KEY_BRACELEFT ,"BraceLeft"},
  211. {KEY_BAR ,"Bar"},
  212. {KEY_BRACERIGHT ,"BraceRight"},
  213. {KEY_ASCIITILDE ,"AsciiTilde"},
  214. {KEY_NOBREAKSPACE ,"NoBreakSpace"},
  215. {KEY_EXCLAMDOWN ,"ExclamDown"},
  216. {KEY_CENT ,"Cent"},
  217. {KEY_STERLING ,"Sterling"},
  218. {KEY_CURRENCY ,"Currency"},
  219. {KEY_YEN ,"Yen"},
  220. {KEY_BROKENBAR ,"BrokenBar"},
  221. {KEY_SECTION ,"Section"},
  222. {KEY_DIAERESIS ,"Diaeresis"},
  223. {KEY_COPYRIGHT ,"Copyright"},
  224. {KEY_ORDFEMININE ,"Ordfeminine"},
  225. {KEY_GUILLEMOTLEFT ,"GuillemotLeft"},
  226. {KEY_NOTSIGN ,"NotSign"},
  227. {KEY_HYPHEN ,"Hyphen"},
  228. {KEY_REGISTERED ,"Registered"},
  229. {KEY_MACRON ,"Macron"},
  230. {KEY_DEGREE ,"Degree"},
  231. {KEY_PLUSMINUS ,"PlusMinus"},
  232. {KEY_TWOSUPERIOR ,"TwoSuperior"},
  233. {KEY_THREESUPERIOR ,"ThreeSuperior"},
  234. {KEY_ACUTE ,"Acute"},
  235. {KEY_MU ,"Mu"},
  236. {KEY_PARAGRAPH ,"Paragraph"},
  237. {KEY_PERIODCENTERED ,"PeriodCentered"},
  238. {KEY_CEDILLA ,"Cedilla"},
  239. {KEY_ONESUPERIOR ,"OneSuperior"},
  240. {KEY_MASCULINE ,"Masculine"},
  241. {KEY_GUILLEMOTRIGHT ,"GuillemotRight"},
  242. {KEY_ONEQUARTER ,"OneQuarter"},
  243. {KEY_ONEHALF ,"OneHalf"},
  244. {KEY_THREEQUARTERS ,"ThreeQuarters"},
  245. {KEY_QUESTIONDOWN ,"QuestionDown"},
  246. {KEY_AGRAVE ,"Agrave"},
  247. {KEY_AACUTE ,"Aacute"},
  248. {KEY_ACIRCUMFLEX ,"AcircumFlex"},
  249. {KEY_ATILDE ,"Atilde"},
  250. {KEY_ADIAERESIS ,"Adiaeresis"},
  251. {KEY_ARING ,"Aring"},
  252. {KEY_AE ,"Ae"},
  253. {KEY_CCEDILLA ,"Ccedilla"},
  254. {KEY_EGRAVE ,"Egrave"},
  255. {KEY_EACUTE ,"Eacute"},
  256. {KEY_ECIRCUMFLEX ,"Ecircumflex"},
  257. {KEY_EDIAERESIS ,"Ediaeresis"},
  258. {KEY_IGRAVE ,"Igrave"},
  259. {KEY_IACUTE ,"Iacute"},
  260. {KEY_ICIRCUMFLEX ,"Icircumflex"},
  261. {KEY_IDIAERESIS ,"Idiaeresis"},
  262. {KEY_ETH ,"Eth"},
  263. {KEY_NTILDE ,"Ntilde"},
  264. {KEY_OGRAVE ,"Ograve"},
  265. {KEY_OACUTE ,"Oacute"},
  266. {KEY_OCIRCUMFLEX ,"Ocircumflex"},
  267. {KEY_OTILDE ,"Otilde"},
  268. {KEY_ODIAERESIS ,"Odiaeresis"},
  269. {KEY_MULTIPLY ,"Multiply"},
  270. {KEY_OOBLIQUE ,"Ooblique"},
  271. {KEY_UGRAVE ,"Ugrave"},
  272. {KEY_UACUTE ,"Uacute"},
  273. {KEY_UCIRCUMFLEX ,"Ucircumflex"},
  274. {KEY_UDIAERESIS ,"Udiaeresis"},
  275. {KEY_YACUTE ,"Yacute"},
  276. {KEY_THORN ,"Thorn"},
  277. {KEY_SSHARP ,"Ssharp"},
  278. {KEY_DIVISION ,"Division"},
  279. {KEY_YDIAERESIS ,"Ydiaeresis"},
  280. {0 ,0}
  281. /* clang-format on */
  282. };
  283. bool keycode_has_unicode(uint32_t p_keycode) {
  284. switch (p_keycode) {
  285. case KEY_ESCAPE:
  286. case KEY_TAB:
  287. case KEY_BACKTAB:
  288. case KEY_BACKSPACE:
  289. case KEY_RETURN:
  290. case KEY_ENTER:
  291. case KEY_INSERT:
  292. case KEY_DELETE:
  293. case KEY_PAUSE:
  294. case KEY_PRINT:
  295. case KEY_SYSREQ:
  296. case KEY_CLEAR:
  297. case KEY_HOME:
  298. case KEY_END:
  299. case KEY_LEFT:
  300. case KEY_UP:
  301. case KEY_RIGHT:
  302. case KEY_DOWN:
  303. case KEY_PAGEUP:
  304. case KEY_PAGEDOWN:
  305. case KEY_SHIFT:
  306. case KEY_CONTROL:
  307. case KEY_META:
  308. case KEY_ALT:
  309. case KEY_CAPSLOCK:
  310. case KEY_NUMLOCK:
  311. case KEY_SCROLLLOCK:
  312. case KEY_F1:
  313. case KEY_F2:
  314. case KEY_F3:
  315. case KEY_F4:
  316. case KEY_F5:
  317. case KEY_F6:
  318. case KEY_F7:
  319. case KEY_F8:
  320. case KEY_F9:
  321. case KEY_F10:
  322. case KEY_F11:
  323. case KEY_F12:
  324. case KEY_F13:
  325. case KEY_F14:
  326. case KEY_F15:
  327. case KEY_F16:
  328. case KEY_KP_ENTER:
  329. case KEY_SUPER_L:
  330. case KEY_SUPER_R:
  331. case KEY_MENU:
  332. case KEY_HYPER_L:
  333. case KEY_HYPER_R:
  334. case KEY_HELP:
  335. case KEY_DIRECTION_L:
  336. case KEY_DIRECTION_R:
  337. case KEY_BACK:
  338. case KEY_FORWARD:
  339. case KEY_STOP:
  340. case KEY_REFRESH:
  341. case KEY_VOLUMEDOWN:
  342. case KEY_VOLUMEMUTE:
  343. case KEY_VOLUMEUP:
  344. case KEY_BASSBOOST:
  345. case KEY_BASSUP:
  346. case KEY_BASSDOWN:
  347. case KEY_TREBLEUP:
  348. case KEY_TREBLEDOWN:
  349. case KEY_MEDIAPLAY:
  350. case KEY_MEDIASTOP:
  351. case KEY_MEDIAPREVIOUS:
  352. case KEY_MEDIANEXT:
  353. case KEY_MEDIARECORD:
  354. case KEY_HOMEPAGE:
  355. case KEY_FAVORITES:
  356. case KEY_SEARCH:
  357. case KEY_STANDBY:
  358. case KEY_OPENURL:
  359. case KEY_LAUNCHMAIL:
  360. case KEY_LAUNCHMEDIA:
  361. case KEY_LAUNCH0:
  362. case KEY_LAUNCH1:
  363. case KEY_LAUNCH2:
  364. case KEY_LAUNCH3:
  365. case KEY_LAUNCH4:
  366. case KEY_LAUNCH5:
  367. case KEY_LAUNCH6:
  368. case KEY_LAUNCH7:
  369. case KEY_LAUNCH8:
  370. case KEY_LAUNCH9:
  371. case KEY_LAUNCHA:
  372. case KEY_LAUNCHB:
  373. case KEY_LAUNCHC:
  374. case KEY_LAUNCHD:
  375. case KEY_LAUNCHE:
  376. case KEY_LAUNCHF:
  377. return false;
  378. }
  379. return true;
  380. }
  381. String keycode_get_string(uint32_t p_code) {
  382. String codestr;
  383. if (p_code & KEY_MASK_SHIFT)
  384. codestr += "Shift+";
  385. if (p_code & KEY_MASK_ALT)
  386. codestr += "Alt+";
  387. if (p_code & KEY_MASK_CTRL)
  388. codestr += "Ctrl+";
  389. if (p_code & KEY_MASK_META)
  390. codestr += "Meta+";
  391. p_code &= KEY_CODE_MASK;
  392. const _KeyCodeText *kct = &_keycodes[0];
  393. while (kct->text) {
  394. if (kct->code == (int)p_code) {
  395. codestr += kct->text;
  396. return codestr;
  397. }
  398. kct++;
  399. }
  400. codestr += String::chr(p_code);
  401. return codestr;
  402. }
  403. int find_keycode(const String &p_code) {
  404. const _KeyCodeText *kct = &_keycodes[0];
  405. while (kct->text) {
  406. if (p_code.nocasecmp_to(kct->text) == 0) {
  407. return kct->code;
  408. }
  409. kct++;
  410. }
  411. return 0;
  412. }
  413. struct _KeyCodeReplace {
  414. int from;
  415. int to;
  416. };
  417. static const _KeyCodeReplace _keycode_replace_qwertz[] = {
  418. { KEY_Y, KEY_Z },
  419. { KEY_Z, KEY_Y },
  420. { 0, 0 }
  421. };
  422. static const _KeyCodeReplace _keycode_replace_azerty[] = {
  423. { KEY_W, KEY_Z },
  424. { KEY_Z, KEY_W },
  425. { KEY_A, KEY_Q },
  426. { KEY_Q, KEY_A },
  427. { KEY_SEMICOLON, KEY_M },
  428. { KEY_M, KEY_SEMICOLON },
  429. { 0, 0 }
  430. };
  431. static const _KeyCodeReplace _keycode_replace_qzerty[] = {
  432. { KEY_W, KEY_Z },
  433. { KEY_Z, KEY_W },
  434. { KEY_SEMICOLON, KEY_M },
  435. { KEY_M, KEY_SEMICOLON },
  436. { 0, 0 }
  437. };
  438. static const _KeyCodeReplace _keycode_replace_dvorak[] = {
  439. { KEY_UNDERSCORE, KEY_BRACELEFT },
  440. { KEY_EQUAL, KEY_BRACERIGHT },
  441. { KEY_Q, KEY_APOSTROPHE },
  442. { KEY_W, KEY_COMMA },
  443. { KEY_E, KEY_PERIOD },
  444. { KEY_R, KEY_P },
  445. { KEY_T, KEY_Y },
  446. { KEY_Y, KEY_F },
  447. { KEY_U, KEY_G },
  448. { KEY_I, KEY_C },
  449. { KEY_O, KEY_R },
  450. { KEY_P, KEY_L },
  451. { KEY_BRACELEFT, KEY_SLASH },
  452. { KEY_BRACERIGHT, KEY_EQUAL },
  453. { KEY_A, KEY_A },
  454. { KEY_S, KEY_O },
  455. { KEY_D, KEY_E },
  456. { KEY_F, KEY_U },
  457. { KEY_G, KEY_I },
  458. { KEY_H, KEY_D },
  459. { KEY_J, KEY_H },
  460. { KEY_K, KEY_T },
  461. { KEY_L, KEY_N },
  462. { KEY_SEMICOLON, KEY_S },
  463. { KEY_APOSTROPHE, KEY_UNDERSCORE },
  464. { KEY_Z, KEY_SEMICOLON },
  465. { KEY_X, KEY_Q },
  466. { KEY_C, KEY_J },
  467. { KEY_V, KEY_K },
  468. { KEY_B, KEY_X },
  469. { KEY_N, KEY_B },
  470. { KEY_M, KEY_M },
  471. { KEY_COMMA, KEY_W },
  472. { KEY_PERIOD, KEY_V },
  473. { KEY_SLASH, KEY_Z },
  474. { 0, 0 }
  475. };
  476. static const _KeyCodeReplace _keycode_replace_neo[] = {
  477. { 0, 0 }
  478. };
  479. static const _KeyCodeReplace _keycode_replace_colemak[] = {
  480. { KEY_E, KEY_F },
  481. { KEY_R, KEY_P },
  482. { KEY_T, KEY_G },
  483. { KEY_Y, KEY_J },
  484. { KEY_U, KEY_L },
  485. { KEY_I, KEY_U },
  486. { KEY_O, KEY_Y },
  487. { KEY_P, KEY_SEMICOLON },
  488. { KEY_S, KEY_R },
  489. { KEY_D, KEY_S },
  490. { KEY_F, KEY_T },
  491. { KEY_G, KEY_D },
  492. { KEY_J, KEY_N },
  493. { KEY_K, KEY_E },
  494. { KEY_L, KEY_I },
  495. { KEY_SEMICOLON, KEY_O },
  496. { KEY_N, KEY_K },
  497. { 0, 0 }
  498. };
  499. int latin_keyboard_keycode_convert(int p_keycode) {
  500. const _KeyCodeReplace *kcr = NULL;
  501. switch (OS::get_singleton()->get_latin_keyboard_variant()) {
  502. case OS::LATIN_KEYBOARD_QWERTY: return p_keycode; break;
  503. case OS::LATIN_KEYBOARD_QWERTZ: kcr = _keycode_replace_qwertz; break;
  504. case OS::LATIN_KEYBOARD_AZERTY: kcr = _keycode_replace_azerty; break;
  505. case OS::LATIN_KEYBOARD_QZERTY: kcr = _keycode_replace_qzerty; break;
  506. case OS::LATIN_KEYBOARD_DVORAK: kcr = _keycode_replace_dvorak; break;
  507. case OS::LATIN_KEYBOARD_NEO: kcr = _keycode_replace_neo; break;
  508. default: return p_keycode;
  509. }
  510. if (!kcr) {
  511. return p_keycode;
  512. }
  513. while (kcr->from) {
  514. if (kcr->from == p_keycode)
  515. return kcr->to;
  516. kcr++;
  517. }
  518. return p_keycode;
  519. }