SDL_keymap.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #include "SDL_keymap_c.h"
  20. #include "SDL_keyboard_c.h"
  21. #include "../SDL_hashtable.h"
  22. struct SDL_Keymap
  23. {
  24. SDL_HashTable *scancode_to_keycode;
  25. SDL_HashTable *keycode_to_scancode;
  26. };
  27. static SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate);
  28. static SDL_Scancode SDL_GetDefaultScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate);
  29. SDL_Keymap *SDL_CreateKeymap(void)
  30. {
  31. SDL_Keymap *keymap = (SDL_Keymap *)SDL_malloc(sizeof(*keymap));
  32. if (!keymap) {
  33. return NULL;
  34. }
  35. keymap->scancode_to_keycode = SDL_CreateHashTable(NULL, 64, SDL_HashID, SDL_KeyMatchID, NULL, false);
  36. keymap->keycode_to_scancode = SDL_CreateHashTable(NULL, 64, SDL_HashID, SDL_KeyMatchID, NULL, false);
  37. if (!keymap->scancode_to_keycode || !keymap->keycode_to_scancode) {
  38. SDL_DestroyKeymap(keymap);
  39. return NULL;
  40. }
  41. return keymap;
  42. }
  43. static SDL_Keymod NormalizeModifierStateForKeymap(SDL_Keymod modstate)
  44. {
  45. // The modifiers that affect the keymap are: SHIFT, CAPS, ALT, and MODE
  46. modstate &= (SDL_KMOD_SHIFT | SDL_KMOD_CAPS | SDL_KMOD_ALT | SDL_KMOD_MODE);
  47. // If either right or left Shift are set, set both in the output
  48. if (modstate & SDL_KMOD_SHIFT) {
  49. modstate |= SDL_KMOD_SHIFT;
  50. }
  51. // If either right or left Alt are set, set both in the output
  52. if (modstate & SDL_KMOD_ALT) {
  53. modstate |= SDL_KMOD_ALT;
  54. }
  55. return modstate;
  56. }
  57. void SDL_SetKeymapEntry(SDL_Keymap *keymap, SDL_Scancode scancode, SDL_Keymod modstate, SDL_Keycode keycode)
  58. {
  59. if (!keymap) {
  60. return;
  61. }
  62. if (keycode == SDL_GetKeymapKeycode(keymap, scancode, modstate)) {
  63. return;
  64. }
  65. Uint32 key = ((Uint32)NormalizeModifierStateForKeymap(modstate) << 16) | scancode;
  66. const void *value;
  67. if (SDL_FindInHashTable(keymap->scancode_to_keycode, (void *)(uintptr_t)key, &value)) {
  68. // Changing the mapping, need to remove the existing entry from the keymap
  69. SDL_RemoveFromHashTable(keymap->scancode_to_keycode, (void *)(uintptr_t)key);
  70. SDL_RemoveFromHashTable(keymap->keycode_to_scancode, value);
  71. }
  72. SDL_InsertIntoHashTable(keymap->scancode_to_keycode, (void *)(uintptr_t)key, (void *)(uintptr_t)keycode);
  73. SDL_InsertIntoHashTable(keymap->keycode_to_scancode, (void *)(uintptr_t)keycode, (void *)(uintptr_t)key);
  74. }
  75. SDL_Keycode SDL_GetKeymapKeycode(SDL_Keymap *keymap, SDL_Scancode scancode, SDL_Keymod modstate)
  76. {
  77. SDL_Keycode keycode;
  78. Uint32 key = ((Uint32)NormalizeModifierStateForKeymap(modstate) << 16) | scancode;
  79. const void *value;
  80. if (keymap && SDL_FindInHashTable(keymap->scancode_to_keycode, (void *)(uintptr_t)key, &value)) {
  81. keycode = (SDL_Keycode)(uintptr_t)value;
  82. } else {
  83. keycode = SDL_GetDefaultKeyFromScancode(scancode, modstate);
  84. }
  85. return keycode;
  86. }
  87. SDL_Scancode SDL_GetKeymapScancode(SDL_Keymap *keymap, SDL_Keycode keycode, SDL_Keymod *modstate)
  88. {
  89. SDL_Scancode scancode;
  90. const void *value;
  91. if (keymap && SDL_FindInHashTable(keymap->keycode_to_scancode, (void *)(uintptr_t)keycode, &value)) {
  92. scancode = (SDL_Scancode)((uintptr_t)value & 0xFFFF);
  93. if (modstate) {
  94. *modstate = (SDL_Keymod)((uintptr_t)value >> 16);
  95. }
  96. } else {
  97. scancode = SDL_GetDefaultScancodeFromKey(keycode, modstate);
  98. }
  99. return scancode;
  100. }
  101. void SDL_DestroyKeymap(SDL_Keymap *keymap)
  102. {
  103. if (!keymap) {
  104. return;
  105. }
  106. SDL_DestroyHashTable(keymap->scancode_to_keycode);
  107. SDL_DestroyHashTable(keymap->keycode_to_scancode);
  108. SDL_free(keymap);
  109. }
  110. static const SDL_Keycode normal_default_symbols[] = {
  111. SDLK_1,
  112. SDLK_2,
  113. SDLK_3,
  114. SDLK_4,
  115. SDLK_5,
  116. SDLK_6,
  117. SDLK_7,
  118. SDLK_8,
  119. SDLK_9,
  120. SDLK_0,
  121. SDLK_RETURN,
  122. SDLK_ESCAPE,
  123. SDLK_BACKSPACE,
  124. SDLK_TAB,
  125. SDLK_SPACE,
  126. SDLK_MINUS,
  127. SDLK_EQUALS,
  128. SDLK_LEFTBRACKET,
  129. SDLK_RIGHTBRACKET,
  130. SDLK_BACKSLASH,
  131. SDLK_HASH,
  132. SDLK_SEMICOLON,
  133. SDLK_APOSTROPHE,
  134. SDLK_GRAVE,
  135. SDLK_COMMA,
  136. SDLK_PERIOD,
  137. SDLK_SLASH,
  138. };
  139. static const SDL_Keycode shifted_default_symbols[] = {
  140. SDLK_EXCLAIM,
  141. SDLK_AT,
  142. SDLK_HASH,
  143. SDLK_DOLLAR,
  144. SDLK_PERCENT,
  145. SDLK_CARET,
  146. SDLK_AMPERSAND,
  147. SDLK_ASTERISK,
  148. SDLK_LEFTPAREN,
  149. SDLK_RIGHTPAREN,
  150. SDLK_RETURN,
  151. SDLK_ESCAPE,
  152. SDLK_BACKSPACE,
  153. SDLK_TAB,
  154. SDLK_SPACE,
  155. SDLK_UNDERSCORE,
  156. SDLK_PLUS,
  157. SDLK_LEFTBRACE,
  158. SDLK_RIGHTBRACE,
  159. SDLK_PIPE,
  160. SDLK_HASH,
  161. SDLK_COLON,
  162. SDLK_DBLAPOSTROPHE,
  163. SDLK_TILDE,
  164. SDLK_LESS,
  165. SDLK_GREATER,
  166. SDLK_QUESTION
  167. };
  168. static SDL_Keycode SDL_GetDefaultKeyFromScancode(SDL_Scancode scancode, SDL_Keymod modstate)
  169. {
  170. if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
  171. SDL_InvalidParamError("scancode");
  172. return SDLK_UNKNOWN;
  173. }
  174. if (scancode < SDL_SCANCODE_A) {
  175. return SDLK_UNKNOWN;
  176. }
  177. if (scancode < SDL_SCANCODE_1) {
  178. bool shifted = (modstate & SDL_KMOD_SHIFT) ? true : false;
  179. #ifdef SDL_PLATFORM_APPLE
  180. // Apple maps to upper case for either shift or capslock inclusive
  181. if (modstate & SDL_KMOD_CAPS) {
  182. shifted = true;
  183. }
  184. #else
  185. if (modstate & SDL_KMOD_CAPS) {
  186. shifted = !shifted;
  187. }
  188. #endif
  189. if (modstate & SDL_KMOD_MODE) {
  190. return SDLK_UNKNOWN;
  191. }
  192. if (!shifted) {
  193. return (SDL_Keycode)('a' + scancode - SDL_SCANCODE_A);
  194. } else {
  195. return (SDL_Keycode)('A' + scancode - SDL_SCANCODE_A);
  196. }
  197. }
  198. if (scancode < SDL_SCANCODE_CAPSLOCK) {
  199. bool shifted = (modstate & SDL_KMOD_SHIFT) ? true : false;
  200. if (modstate & SDL_KMOD_MODE) {
  201. return SDLK_UNKNOWN;
  202. }
  203. if (!shifted) {
  204. return normal_default_symbols[scancode - SDL_SCANCODE_1];
  205. } else {
  206. return shifted_default_symbols[scancode - SDL_SCANCODE_1];
  207. }
  208. }
  209. // These scancodes are not mapped to printable keycodes
  210. switch (scancode) {
  211. case SDL_SCANCODE_DELETE:
  212. return SDLK_DELETE;
  213. case SDL_SCANCODE_CAPSLOCK:
  214. return SDLK_CAPSLOCK;
  215. case SDL_SCANCODE_F1:
  216. return SDLK_F1;
  217. case SDL_SCANCODE_F2:
  218. return SDLK_F2;
  219. case SDL_SCANCODE_F3:
  220. return SDLK_F3;
  221. case SDL_SCANCODE_F4:
  222. return SDLK_F4;
  223. case SDL_SCANCODE_F5:
  224. return SDLK_F5;
  225. case SDL_SCANCODE_F6:
  226. return SDLK_F6;
  227. case SDL_SCANCODE_F7:
  228. return SDLK_F7;
  229. case SDL_SCANCODE_F8:
  230. return SDLK_F8;
  231. case SDL_SCANCODE_F9:
  232. return SDLK_F9;
  233. case SDL_SCANCODE_F10:
  234. return SDLK_F10;
  235. case SDL_SCANCODE_F11:
  236. return SDLK_F11;
  237. case SDL_SCANCODE_F12:
  238. return SDLK_F12;
  239. case SDL_SCANCODE_PRINTSCREEN:
  240. return SDLK_PRINTSCREEN;
  241. case SDL_SCANCODE_SCROLLLOCK:
  242. return SDLK_SCROLLLOCK;
  243. case SDL_SCANCODE_PAUSE:
  244. return SDLK_PAUSE;
  245. case SDL_SCANCODE_INSERT:
  246. return SDLK_INSERT;
  247. case SDL_SCANCODE_HOME:
  248. return SDLK_HOME;
  249. case SDL_SCANCODE_PAGEUP:
  250. return SDLK_PAGEUP;
  251. case SDL_SCANCODE_END:
  252. return SDLK_END;
  253. case SDL_SCANCODE_PAGEDOWN:
  254. return SDLK_PAGEDOWN;
  255. case SDL_SCANCODE_RIGHT:
  256. return SDLK_RIGHT;
  257. case SDL_SCANCODE_LEFT:
  258. return SDLK_LEFT;
  259. case SDL_SCANCODE_DOWN:
  260. return SDLK_DOWN;
  261. case SDL_SCANCODE_UP:
  262. return SDLK_UP;
  263. case SDL_SCANCODE_NUMLOCKCLEAR:
  264. return SDLK_NUMLOCKCLEAR;
  265. case SDL_SCANCODE_KP_DIVIDE:
  266. return SDLK_KP_DIVIDE;
  267. case SDL_SCANCODE_KP_MULTIPLY:
  268. return SDLK_KP_MULTIPLY;
  269. case SDL_SCANCODE_KP_MINUS:
  270. return SDLK_KP_MINUS;
  271. case SDL_SCANCODE_KP_PLUS:
  272. return SDLK_KP_PLUS;
  273. case SDL_SCANCODE_KP_ENTER:
  274. return SDLK_KP_ENTER;
  275. case SDL_SCANCODE_KP_1:
  276. return SDLK_KP_1;
  277. case SDL_SCANCODE_KP_2:
  278. return SDLK_KP_2;
  279. case SDL_SCANCODE_KP_3:
  280. return SDLK_KP_3;
  281. case SDL_SCANCODE_KP_4:
  282. return SDLK_KP_4;
  283. case SDL_SCANCODE_KP_5:
  284. return SDLK_KP_5;
  285. case SDL_SCANCODE_KP_6:
  286. return SDLK_KP_6;
  287. case SDL_SCANCODE_KP_7:
  288. return SDLK_KP_7;
  289. case SDL_SCANCODE_KP_8:
  290. return SDLK_KP_8;
  291. case SDL_SCANCODE_KP_9:
  292. return SDLK_KP_9;
  293. case SDL_SCANCODE_KP_0:
  294. return SDLK_KP_0;
  295. case SDL_SCANCODE_KP_PERIOD:
  296. return SDLK_KP_PERIOD;
  297. case SDL_SCANCODE_APPLICATION:
  298. return SDLK_APPLICATION;
  299. case SDL_SCANCODE_POWER:
  300. return SDLK_POWER;
  301. case SDL_SCANCODE_KP_EQUALS:
  302. return SDLK_KP_EQUALS;
  303. case SDL_SCANCODE_F13:
  304. return SDLK_F13;
  305. case SDL_SCANCODE_F14:
  306. return SDLK_F14;
  307. case SDL_SCANCODE_F15:
  308. return SDLK_F15;
  309. case SDL_SCANCODE_F16:
  310. return SDLK_F16;
  311. case SDL_SCANCODE_F17:
  312. return SDLK_F17;
  313. case SDL_SCANCODE_F18:
  314. return SDLK_F18;
  315. case SDL_SCANCODE_F19:
  316. return SDLK_F19;
  317. case SDL_SCANCODE_F20:
  318. return SDLK_F20;
  319. case SDL_SCANCODE_F21:
  320. return SDLK_F21;
  321. case SDL_SCANCODE_F22:
  322. return SDLK_F22;
  323. case SDL_SCANCODE_F23:
  324. return SDLK_F23;
  325. case SDL_SCANCODE_F24:
  326. return SDLK_F24;
  327. case SDL_SCANCODE_EXECUTE:
  328. return SDLK_EXECUTE;
  329. case SDL_SCANCODE_HELP:
  330. return SDLK_HELP;
  331. case SDL_SCANCODE_MENU:
  332. return SDLK_MENU;
  333. case SDL_SCANCODE_SELECT:
  334. return SDLK_SELECT;
  335. case SDL_SCANCODE_STOP:
  336. return SDLK_STOP;
  337. case SDL_SCANCODE_AGAIN:
  338. return SDLK_AGAIN;
  339. case SDL_SCANCODE_UNDO:
  340. return SDLK_UNDO;
  341. case SDL_SCANCODE_CUT:
  342. return SDLK_CUT;
  343. case SDL_SCANCODE_COPY:
  344. return SDLK_COPY;
  345. case SDL_SCANCODE_PASTE:
  346. return SDLK_PASTE;
  347. case SDL_SCANCODE_FIND:
  348. return SDLK_FIND;
  349. case SDL_SCANCODE_MUTE:
  350. return SDLK_MUTE;
  351. case SDL_SCANCODE_VOLUMEUP:
  352. return SDLK_VOLUMEUP;
  353. case SDL_SCANCODE_VOLUMEDOWN:
  354. return SDLK_VOLUMEDOWN;
  355. case SDL_SCANCODE_KP_COMMA:
  356. return SDLK_KP_COMMA;
  357. case SDL_SCANCODE_KP_EQUALSAS400:
  358. return SDLK_KP_EQUALSAS400;
  359. case SDL_SCANCODE_ALTERASE:
  360. return SDLK_ALTERASE;
  361. case SDL_SCANCODE_SYSREQ:
  362. return SDLK_SYSREQ;
  363. case SDL_SCANCODE_CANCEL:
  364. return SDLK_CANCEL;
  365. case SDL_SCANCODE_CLEAR:
  366. return SDLK_CLEAR;
  367. case SDL_SCANCODE_PRIOR:
  368. return SDLK_PRIOR;
  369. case SDL_SCANCODE_RETURN2:
  370. return SDLK_RETURN2;
  371. case SDL_SCANCODE_SEPARATOR:
  372. return SDLK_SEPARATOR;
  373. case SDL_SCANCODE_OUT:
  374. return SDLK_OUT;
  375. case SDL_SCANCODE_OPER:
  376. return SDLK_OPER;
  377. case SDL_SCANCODE_CLEARAGAIN:
  378. return SDLK_CLEARAGAIN;
  379. case SDL_SCANCODE_CRSEL:
  380. return SDLK_CRSEL;
  381. case SDL_SCANCODE_EXSEL:
  382. return SDLK_EXSEL;
  383. case SDL_SCANCODE_KP_00:
  384. return SDLK_KP_00;
  385. case SDL_SCANCODE_KP_000:
  386. return SDLK_KP_000;
  387. case SDL_SCANCODE_THOUSANDSSEPARATOR:
  388. return SDLK_THOUSANDSSEPARATOR;
  389. case SDL_SCANCODE_DECIMALSEPARATOR:
  390. return SDLK_DECIMALSEPARATOR;
  391. case SDL_SCANCODE_CURRENCYUNIT:
  392. return SDLK_CURRENCYUNIT;
  393. case SDL_SCANCODE_CURRENCYSUBUNIT:
  394. return SDLK_CURRENCYSUBUNIT;
  395. case SDL_SCANCODE_KP_LEFTPAREN:
  396. return SDLK_KP_LEFTPAREN;
  397. case SDL_SCANCODE_KP_RIGHTPAREN:
  398. return SDLK_KP_RIGHTPAREN;
  399. case SDL_SCANCODE_KP_LEFTBRACE:
  400. return SDLK_KP_LEFTBRACE;
  401. case SDL_SCANCODE_KP_RIGHTBRACE:
  402. return SDLK_KP_RIGHTBRACE;
  403. case SDL_SCANCODE_KP_TAB:
  404. return SDLK_KP_TAB;
  405. case SDL_SCANCODE_KP_BACKSPACE:
  406. return SDLK_KP_BACKSPACE;
  407. case SDL_SCANCODE_KP_A:
  408. return SDLK_KP_A;
  409. case SDL_SCANCODE_KP_B:
  410. return SDLK_KP_B;
  411. case SDL_SCANCODE_KP_C:
  412. return SDLK_KP_C;
  413. case SDL_SCANCODE_KP_D:
  414. return SDLK_KP_D;
  415. case SDL_SCANCODE_KP_E:
  416. return SDLK_KP_E;
  417. case SDL_SCANCODE_KP_F:
  418. return SDLK_KP_F;
  419. case SDL_SCANCODE_KP_XOR:
  420. return SDLK_KP_XOR;
  421. case SDL_SCANCODE_KP_POWER:
  422. return SDLK_KP_POWER;
  423. case SDL_SCANCODE_KP_PERCENT:
  424. return SDLK_KP_PERCENT;
  425. case SDL_SCANCODE_KP_LESS:
  426. return SDLK_KP_LESS;
  427. case SDL_SCANCODE_KP_GREATER:
  428. return SDLK_KP_GREATER;
  429. case SDL_SCANCODE_KP_AMPERSAND:
  430. return SDLK_KP_AMPERSAND;
  431. case SDL_SCANCODE_KP_DBLAMPERSAND:
  432. return SDLK_KP_DBLAMPERSAND;
  433. case SDL_SCANCODE_KP_VERTICALBAR:
  434. return SDLK_KP_VERTICALBAR;
  435. case SDL_SCANCODE_KP_DBLVERTICALBAR:
  436. return SDLK_KP_DBLVERTICALBAR;
  437. case SDL_SCANCODE_KP_COLON:
  438. return SDLK_KP_COLON;
  439. case SDL_SCANCODE_KP_HASH:
  440. return SDLK_KP_HASH;
  441. case SDL_SCANCODE_KP_SPACE:
  442. return SDLK_KP_SPACE;
  443. case SDL_SCANCODE_KP_AT:
  444. return SDLK_KP_AT;
  445. case SDL_SCANCODE_KP_EXCLAM:
  446. return SDLK_KP_EXCLAM;
  447. case SDL_SCANCODE_KP_MEMSTORE:
  448. return SDLK_KP_MEMSTORE;
  449. case SDL_SCANCODE_KP_MEMRECALL:
  450. return SDLK_KP_MEMRECALL;
  451. case SDL_SCANCODE_KP_MEMCLEAR:
  452. return SDLK_KP_MEMCLEAR;
  453. case SDL_SCANCODE_KP_MEMADD:
  454. return SDLK_KP_MEMADD;
  455. case SDL_SCANCODE_KP_MEMSUBTRACT:
  456. return SDLK_KP_MEMSUBTRACT;
  457. case SDL_SCANCODE_KP_MEMMULTIPLY:
  458. return SDLK_KP_MEMMULTIPLY;
  459. case SDL_SCANCODE_KP_MEMDIVIDE:
  460. return SDLK_KP_MEMDIVIDE;
  461. case SDL_SCANCODE_KP_PLUSMINUS:
  462. return SDLK_KP_PLUSMINUS;
  463. case SDL_SCANCODE_KP_CLEAR:
  464. return SDLK_KP_CLEAR;
  465. case SDL_SCANCODE_KP_CLEARENTRY:
  466. return SDLK_KP_CLEARENTRY;
  467. case SDL_SCANCODE_KP_BINARY:
  468. return SDLK_KP_BINARY;
  469. case SDL_SCANCODE_KP_OCTAL:
  470. return SDLK_KP_OCTAL;
  471. case SDL_SCANCODE_KP_DECIMAL:
  472. return SDLK_KP_DECIMAL;
  473. case SDL_SCANCODE_KP_HEXADECIMAL:
  474. return SDLK_KP_HEXADECIMAL;
  475. case SDL_SCANCODE_LCTRL:
  476. return SDLK_LCTRL;
  477. case SDL_SCANCODE_LSHIFT:
  478. return SDLK_LSHIFT;
  479. case SDL_SCANCODE_LALT:
  480. return SDLK_LALT;
  481. case SDL_SCANCODE_LGUI:
  482. return SDLK_LGUI;
  483. case SDL_SCANCODE_RCTRL:
  484. return SDLK_RCTRL;
  485. case SDL_SCANCODE_RSHIFT:
  486. return SDLK_RSHIFT;
  487. case SDL_SCANCODE_RALT:
  488. return SDLK_RALT;
  489. case SDL_SCANCODE_RGUI:
  490. return SDLK_RGUI;
  491. case SDL_SCANCODE_MODE:
  492. return SDLK_MODE;
  493. case SDL_SCANCODE_SLEEP:
  494. return SDLK_SLEEP;
  495. case SDL_SCANCODE_WAKE:
  496. return SDLK_WAKE;
  497. case SDL_SCANCODE_CHANNEL_INCREMENT:
  498. return SDLK_CHANNEL_INCREMENT;
  499. case SDL_SCANCODE_CHANNEL_DECREMENT:
  500. return SDLK_CHANNEL_DECREMENT;
  501. case SDL_SCANCODE_MEDIA_PLAY:
  502. return SDLK_MEDIA_PLAY;
  503. case SDL_SCANCODE_MEDIA_PAUSE:
  504. return SDLK_MEDIA_PAUSE;
  505. case SDL_SCANCODE_MEDIA_RECORD:
  506. return SDLK_MEDIA_RECORD;
  507. case SDL_SCANCODE_MEDIA_FAST_FORWARD:
  508. return SDLK_MEDIA_FAST_FORWARD;
  509. case SDL_SCANCODE_MEDIA_REWIND:
  510. return SDLK_MEDIA_REWIND;
  511. case SDL_SCANCODE_MEDIA_NEXT_TRACK:
  512. return SDLK_MEDIA_NEXT_TRACK;
  513. case SDL_SCANCODE_MEDIA_PREVIOUS_TRACK:
  514. return SDLK_MEDIA_PREVIOUS_TRACK;
  515. case SDL_SCANCODE_MEDIA_STOP:
  516. return SDLK_MEDIA_STOP;
  517. case SDL_SCANCODE_MEDIA_EJECT:
  518. return SDLK_MEDIA_EJECT;
  519. case SDL_SCANCODE_MEDIA_PLAY_PAUSE:
  520. return SDLK_MEDIA_PLAY_PAUSE;
  521. case SDL_SCANCODE_MEDIA_SELECT:
  522. return SDLK_MEDIA_SELECT;
  523. case SDL_SCANCODE_AC_NEW:
  524. return SDLK_AC_NEW;
  525. case SDL_SCANCODE_AC_OPEN:
  526. return SDLK_AC_OPEN;
  527. case SDL_SCANCODE_AC_CLOSE:
  528. return SDLK_AC_CLOSE;
  529. case SDL_SCANCODE_AC_EXIT:
  530. return SDLK_AC_EXIT;
  531. case SDL_SCANCODE_AC_SAVE:
  532. return SDLK_AC_SAVE;
  533. case SDL_SCANCODE_AC_PRINT:
  534. return SDLK_AC_PRINT;
  535. case SDL_SCANCODE_AC_PROPERTIES:
  536. return SDLK_AC_PROPERTIES;
  537. case SDL_SCANCODE_AC_SEARCH:
  538. return SDLK_AC_SEARCH;
  539. case SDL_SCANCODE_AC_HOME:
  540. return SDLK_AC_HOME;
  541. case SDL_SCANCODE_AC_BACK:
  542. return SDLK_AC_BACK;
  543. case SDL_SCANCODE_AC_FORWARD:
  544. return SDLK_AC_FORWARD;
  545. case SDL_SCANCODE_AC_STOP:
  546. return SDLK_AC_STOP;
  547. case SDL_SCANCODE_AC_REFRESH:
  548. return SDLK_AC_REFRESH;
  549. case SDL_SCANCODE_AC_BOOKMARKS:
  550. return SDLK_AC_BOOKMARKS;
  551. case SDL_SCANCODE_SOFTLEFT:
  552. return SDLK_SOFTLEFT;
  553. case SDL_SCANCODE_SOFTRIGHT:
  554. return SDLK_SOFTRIGHT;
  555. case SDL_SCANCODE_CALL:
  556. return SDLK_CALL;
  557. case SDL_SCANCODE_ENDCALL:
  558. return SDLK_ENDCALL;
  559. default:
  560. return SDLK_UNKNOWN;
  561. }
  562. }
  563. static SDL_Scancode SDL_GetDefaultScancodeFromKey(SDL_Keycode key, SDL_Keymod *modstate)
  564. {
  565. if (modstate) {
  566. *modstate = SDL_KMOD_NONE;
  567. }
  568. if (key == SDLK_UNKNOWN) {
  569. return SDL_SCANCODE_UNKNOWN;
  570. }
  571. if (key & SDLK_SCANCODE_MASK) {
  572. return (SDL_Scancode)(key & ~SDLK_SCANCODE_MASK);
  573. }
  574. if (key >= SDLK_A && key <= SDLK_Z) {
  575. return (SDL_Scancode)(SDL_SCANCODE_A + key - SDLK_A);
  576. }
  577. if (key >= 'A' && key <= 'Z') {
  578. if (modstate) {
  579. *modstate = SDL_KMOD_SHIFT;
  580. }
  581. return (SDL_Scancode)(SDL_SCANCODE_A + key - 'A');
  582. }
  583. for (int i = 0; i < SDL_arraysize(normal_default_symbols); ++i) {
  584. if (key == normal_default_symbols[i]) {
  585. return(SDL_Scancode)(SDL_SCANCODE_1 + i);
  586. }
  587. }
  588. for (int i = 0; i < SDL_arraysize(shifted_default_symbols); ++i) {
  589. if (key == shifted_default_symbols[i]) {
  590. if (modstate) {
  591. *modstate = SDL_KMOD_SHIFT;
  592. }
  593. return(SDL_Scancode)(SDL_SCANCODE_1 + i);
  594. }
  595. }
  596. if (key == SDLK_DELETE) {
  597. return SDL_SCANCODE_DELETE;
  598. }
  599. return SDL_SCANCODE_UNKNOWN;
  600. }
  601. static const char *SDL_scancode_names[SDL_SCANCODE_COUNT] =
  602. {
  603. /* 0 */ NULL,
  604. /* 1 */ NULL,
  605. /* 2 */ NULL,
  606. /* 3 */ NULL,
  607. /* 4 */ "A",
  608. /* 5 */ "B",
  609. /* 6 */ "C",
  610. /* 7 */ "D",
  611. /* 8 */ "E",
  612. /* 9 */ "F",
  613. /* 10 */ "G",
  614. /* 11 */ "H",
  615. /* 12 */ "I",
  616. /* 13 */ "J",
  617. /* 14 */ "K",
  618. /* 15 */ "L",
  619. /* 16 */ "M",
  620. /* 17 */ "N",
  621. /* 18 */ "O",
  622. /* 19 */ "P",
  623. /* 20 */ "Q",
  624. /* 21 */ "R",
  625. /* 22 */ "S",
  626. /* 23 */ "T",
  627. /* 24 */ "U",
  628. /* 25 */ "V",
  629. /* 26 */ "W",
  630. /* 27 */ "X",
  631. /* 28 */ "Y",
  632. /* 29 */ "Z",
  633. /* 30 */ "1",
  634. /* 31 */ "2",
  635. /* 32 */ "3",
  636. /* 33 */ "4",
  637. /* 34 */ "5",
  638. /* 35 */ "6",
  639. /* 36 */ "7",
  640. /* 37 */ "8",
  641. /* 38 */ "9",
  642. /* 39 */ "0",
  643. /* 40 */ "Return",
  644. /* 41 */ "Escape",
  645. /* 42 */ "Backspace",
  646. /* 43 */ "Tab",
  647. /* 44 */ "Space",
  648. /* 45 */ "-",
  649. /* 46 */ "=",
  650. /* 47 */ "[",
  651. /* 48 */ "]",
  652. /* 49 */ "\\",
  653. /* 50 */ "#",
  654. /* 51 */ ";",
  655. /* 52 */ "'",
  656. /* 53 */ "`",
  657. /* 54 */ ",",
  658. /* 55 */ ".",
  659. /* 56 */ "/",
  660. /* 57 */ "CapsLock",
  661. /* 58 */ "F1",
  662. /* 59 */ "F2",
  663. /* 60 */ "F3",
  664. /* 61 */ "F4",
  665. /* 62 */ "F5",
  666. /* 63 */ "F6",
  667. /* 64 */ "F7",
  668. /* 65 */ "F8",
  669. /* 66 */ "F9",
  670. /* 67 */ "F10",
  671. /* 68 */ "F11",
  672. /* 69 */ "F12",
  673. /* 70 */ "PrintScreen",
  674. /* 71 */ "ScrollLock",
  675. /* 72 */ "Pause",
  676. /* 73 */ "Insert",
  677. /* 74 */ "Home",
  678. /* 75 */ "PageUp",
  679. /* 76 */ "Delete",
  680. /* 77 */ "End",
  681. /* 78 */ "PageDown",
  682. /* 79 */ "Right",
  683. /* 80 */ "Left",
  684. /* 81 */ "Down",
  685. /* 82 */ "Up",
  686. /* 83 */ "Numlock",
  687. /* 84 */ "Keypad /",
  688. /* 85 */ "Keypad *",
  689. /* 86 */ "Keypad -",
  690. /* 87 */ "Keypad +",
  691. /* 88 */ "Keypad Enter",
  692. /* 89 */ "Keypad 1",
  693. /* 90 */ "Keypad 2",
  694. /* 91 */ "Keypad 3",
  695. /* 92 */ "Keypad 4",
  696. /* 93 */ "Keypad 5",
  697. /* 94 */ "Keypad 6",
  698. /* 95 */ "Keypad 7",
  699. /* 96 */ "Keypad 8",
  700. /* 97 */ "Keypad 9",
  701. /* 98 */ "Keypad 0",
  702. /* 99 */ "Keypad .",
  703. /* 100 */ NULL,
  704. /* 101 */ "Application",
  705. /* 102 */ "Power",
  706. /* 103 */ "Keypad =",
  707. /* 104 */ "F13",
  708. /* 105 */ "F14",
  709. /* 106 */ "F15",
  710. /* 107 */ "F16",
  711. /* 108 */ "F17",
  712. /* 109 */ "F18",
  713. /* 110 */ "F19",
  714. /* 111 */ "F20",
  715. /* 112 */ "F21",
  716. /* 113 */ "F22",
  717. /* 114 */ "F23",
  718. /* 115 */ "F24",
  719. /* 116 */ "Execute",
  720. /* 117 */ "Help",
  721. /* 118 */ "Menu",
  722. /* 119 */ "Select",
  723. /* 120 */ "Stop",
  724. /* 121 */ "Again",
  725. /* 122 */ "Undo",
  726. /* 123 */ "Cut",
  727. /* 124 */ "Copy",
  728. /* 125 */ "Paste",
  729. /* 126 */ "Find",
  730. /* 127 */ "Mute",
  731. /* 128 */ "VolumeUp",
  732. /* 129 */ "VolumeDown",
  733. /* 130 */ NULL,
  734. /* 131 */ NULL,
  735. /* 132 */ NULL,
  736. /* 133 */ "Keypad ,",
  737. /* 134 */ "Keypad = (AS400)",
  738. /* 135 */ NULL,
  739. /* 136 */ NULL,
  740. /* 137 */ NULL,
  741. /* 138 */ NULL,
  742. /* 139 */ NULL,
  743. /* 140 */ NULL,
  744. /* 141 */ NULL,
  745. /* 142 */ NULL,
  746. /* 143 */ NULL,
  747. /* 144 */ NULL,
  748. /* 145 */ NULL,
  749. /* 146 */ NULL,
  750. /* 147 */ NULL,
  751. /* 148 */ NULL,
  752. /* 149 */ NULL,
  753. /* 150 */ NULL,
  754. /* 151 */ NULL,
  755. /* 152 */ NULL,
  756. /* 153 */ "AltErase",
  757. /* 154 */ "SysReq",
  758. /* 155 */ "Cancel",
  759. /* 156 */ "Clear",
  760. /* 157 */ "Prior",
  761. /* 158 */ "Return",
  762. /* 159 */ "Separator",
  763. /* 160 */ "Out",
  764. /* 161 */ "Oper",
  765. /* 162 */ "Clear / Again",
  766. /* 163 */ "CrSel",
  767. /* 164 */ "ExSel",
  768. /* 165 */ NULL,
  769. /* 166 */ NULL,
  770. /* 167 */ NULL,
  771. /* 168 */ NULL,
  772. /* 169 */ NULL,
  773. /* 170 */ NULL,
  774. /* 171 */ NULL,
  775. /* 172 */ NULL,
  776. /* 173 */ NULL,
  777. /* 174 */ NULL,
  778. /* 175 */ NULL,
  779. /* 176 */ "Keypad 00",
  780. /* 177 */ "Keypad 000",
  781. /* 178 */ "ThousandsSeparator",
  782. /* 179 */ "DecimalSeparator",
  783. /* 180 */ "CurrencyUnit",
  784. /* 181 */ "CurrencySubUnit",
  785. /* 182 */ "Keypad (",
  786. /* 183 */ "Keypad )",
  787. /* 184 */ "Keypad {",
  788. /* 185 */ "Keypad }",
  789. /* 186 */ "Keypad Tab",
  790. /* 187 */ "Keypad Backspace",
  791. /* 188 */ "Keypad A",
  792. /* 189 */ "Keypad B",
  793. /* 190 */ "Keypad C",
  794. /* 191 */ "Keypad D",
  795. /* 192 */ "Keypad E",
  796. /* 193 */ "Keypad F",
  797. /* 194 */ "Keypad XOR",
  798. /* 195 */ "Keypad ^",
  799. /* 196 */ "Keypad %",
  800. /* 197 */ "Keypad <",
  801. /* 198 */ "Keypad >",
  802. /* 199 */ "Keypad &",
  803. /* 200 */ "Keypad &&",
  804. /* 201 */ "Keypad |",
  805. /* 202 */ "Keypad ||",
  806. /* 203 */ "Keypad :",
  807. /* 204 */ "Keypad #",
  808. /* 205 */ "Keypad Space",
  809. /* 206 */ "Keypad @",
  810. /* 207 */ "Keypad !",
  811. /* 208 */ "Keypad MemStore",
  812. /* 209 */ "Keypad MemRecall",
  813. /* 210 */ "Keypad MemClear",
  814. /* 211 */ "Keypad MemAdd",
  815. /* 212 */ "Keypad MemSubtract",
  816. /* 213 */ "Keypad MemMultiply",
  817. /* 214 */ "Keypad MemDivide",
  818. /* 215 */ "Keypad +/-",
  819. /* 216 */ "Keypad Clear",
  820. /* 217 */ "Keypad ClearEntry",
  821. /* 218 */ "Keypad Binary",
  822. /* 219 */ "Keypad Octal",
  823. /* 220 */ "Keypad Decimal",
  824. /* 221 */ "Keypad Hexadecimal",
  825. /* 222 */ NULL,
  826. /* 223 */ NULL,
  827. /* 224 */ "Left Ctrl",
  828. /* 225 */ "Left Shift",
  829. /* 226 */ "Left Alt",
  830. /* 227 */ "Left GUI",
  831. /* 228 */ "Right Ctrl",
  832. /* 229 */ "Right Shift",
  833. /* 230 */ "Right Alt",
  834. /* 231 */ "Right GUI",
  835. /* 232 */ NULL,
  836. /* 233 */ NULL,
  837. /* 234 */ NULL,
  838. /* 235 */ NULL,
  839. /* 236 */ NULL,
  840. /* 237 */ NULL,
  841. /* 238 */ NULL,
  842. /* 239 */ NULL,
  843. /* 240 */ NULL,
  844. /* 241 */ NULL,
  845. /* 242 */ NULL,
  846. /* 243 */ NULL,
  847. /* 244 */ NULL,
  848. /* 245 */ NULL,
  849. /* 246 */ NULL,
  850. /* 247 */ NULL,
  851. /* 248 */ NULL,
  852. /* 249 */ NULL,
  853. /* 250 */ NULL,
  854. /* 251 */ NULL,
  855. /* 252 */ NULL,
  856. /* 253 */ NULL,
  857. /* 254 */ NULL,
  858. /* 255 */ NULL,
  859. /* 256 */ NULL,
  860. /* 257 */ "ModeSwitch",
  861. /* 258 */ "Sleep",
  862. /* 259 */ "Wake",
  863. /* 260 */ "ChannelUp",
  864. /* 261 */ "ChannelDown",
  865. /* 262 */ "MediaPlay",
  866. /* 263 */ "MediaPause",
  867. /* 264 */ "MediaRecord",
  868. /* 265 */ "MediaFastForward",
  869. /* 266 */ "MediaRewind",
  870. /* 267 */ "MediaTrackNext",
  871. /* 268 */ "MediaTrackPrevious",
  872. /* 269 */ "MediaStop",
  873. /* 270 */ "Eject",
  874. /* 271 */ "MediaPlayPause",
  875. /* 272 */ "MediaSelect",
  876. /* 273 */ "AC New",
  877. /* 274 */ "AC Open",
  878. /* 275 */ "AC Close",
  879. /* 276 */ "AC Exit",
  880. /* 277 */ "AC Save",
  881. /* 278 */ "AC Print",
  882. /* 279 */ "AC Properties",
  883. /* 280 */ "AC Search",
  884. /* 281 */ "AC Home",
  885. /* 282 */ "AC Back",
  886. /* 283 */ "AC Forward",
  887. /* 284 */ "AC Stop",
  888. /* 285 */ "AC Refresh",
  889. /* 286 */ "AC Bookmarks",
  890. /* 287 */ "SoftLeft",
  891. /* 288 */ "SoftRight",
  892. /* 289 */ "Call",
  893. /* 290 */ "EndCall",
  894. };
  895. bool SDL_SetScancodeName(SDL_Scancode scancode, const char *name)
  896. {
  897. if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
  898. return SDL_InvalidParamError("scancode");
  899. }
  900. SDL_scancode_names[scancode] = name;
  901. return true;
  902. }
  903. const char *SDL_GetScancodeName(SDL_Scancode scancode)
  904. {
  905. const char *name;
  906. if (((int)scancode) < SDL_SCANCODE_UNKNOWN || scancode >= SDL_SCANCODE_COUNT) {
  907. SDL_InvalidParamError("scancode");
  908. return "";
  909. }
  910. name = SDL_scancode_names[scancode];
  911. if (!name) {
  912. name = "";
  913. }
  914. // This is pointing to static memory or application managed memory
  915. return name;
  916. }
  917. SDL_Scancode SDL_GetScancodeFromName(const char *name)
  918. {
  919. int i;
  920. if (!name || !*name) {
  921. SDL_InvalidParamError("name");
  922. return SDL_SCANCODE_UNKNOWN;
  923. }
  924. for (i = 0; i < SDL_arraysize(SDL_scancode_names); ++i) {
  925. if (!SDL_scancode_names[i]) {
  926. continue;
  927. }
  928. if (SDL_strcasecmp(name, SDL_scancode_names[i]) == 0) {
  929. return (SDL_Scancode)i;
  930. }
  931. }
  932. SDL_InvalidParamError("name");
  933. return SDL_SCANCODE_UNKNOWN;
  934. }
  935. const char *SDL_GetKeyName(SDL_Keycode key)
  936. {
  937. const bool uppercase = true;
  938. char name[8];
  939. char *end;
  940. if (key & SDLK_SCANCODE_MASK) {
  941. return SDL_GetScancodeName((SDL_Scancode)(key & ~SDLK_SCANCODE_MASK));
  942. }
  943. switch (key) {
  944. case SDLK_RETURN:
  945. return SDL_GetScancodeName(SDL_SCANCODE_RETURN);
  946. case SDLK_ESCAPE:
  947. return SDL_GetScancodeName(SDL_SCANCODE_ESCAPE);
  948. case SDLK_BACKSPACE:
  949. return SDL_GetScancodeName(SDL_SCANCODE_BACKSPACE);
  950. case SDLK_TAB:
  951. return SDL_GetScancodeName(SDL_SCANCODE_TAB);
  952. case SDLK_SPACE:
  953. return SDL_GetScancodeName(SDL_SCANCODE_SPACE);
  954. case SDLK_DELETE:
  955. return SDL_GetScancodeName(SDL_SCANCODE_DELETE);
  956. default:
  957. if (uppercase) {
  958. // SDL_Keycode is defined as the unshifted key on the keyboard,
  959. // but the key name is defined as the letter printed on that key,
  960. // which is usually the shifted capital letter.
  961. if (key > 0x7F || (key >= 'a' && key <= 'z')) {
  962. SDL_Keymap *keymap = SDL_GetCurrentKeymap();
  963. SDL_Keymod modstate;
  964. SDL_Scancode scancode = SDL_GetKeymapScancode(keymap, key, &modstate);
  965. if (scancode != SDL_SCANCODE_UNKNOWN && !(modstate & SDL_KMOD_SHIFT)) {
  966. SDL_Keycode capital = SDL_GetKeymapKeycode(keymap, scancode, SDL_KMOD_SHIFT);
  967. if (capital > 0x7F || (capital >= 'A' && capital <= 'Z')) {
  968. key = capital;
  969. }
  970. }
  971. }
  972. }
  973. end = SDL_UCS4ToUTF8(key, name);
  974. *end = '\0';
  975. return SDL_GetPersistentString(name);
  976. }
  977. }
  978. SDL_Keycode SDL_GetKeyFromName(const char *name)
  979. {
  980. const bool uppercase = true;
  981. SDL_Keycode key;
  982. // Check input
  983. if (!name) {
  984. return SDLK_UNKNOWN;
  985. }
  986. // If it's a single UTF-8 character, then that's the keycode itself
  987. key = *(const unsigned char *)name;
  988. if (key >= 0xF0) {
  989. if (SDL_strlen(name) == 4) {
  990. int i = 0;
  991. key = (Uint16)(name[i] & 0x07) << 18;
  992. key |= (Uint16)(name[++i] & 0x3F) << 12;
  993. key |= (Uint16)(name[++i] & 0x3F) << 6;
  994. key |= (Uint16)(name[++i] & 0x3F);
  995. } else {
  996. key = SDLK_UNKNOWN;
  997. }
  998. } else if (key >= 0xE0) {
  999. if (SDL_strlen(name) == 3) {
  1000. int i = 0;
  1001. key = (Uint16)(name[i] & 0x0F) << 12;
  1002. key |= (Uint16)(name[++i] & 0x3F) << 6;
  1003. key |= (Uint16)(name[++i] & 0x3F);
  1004. } else {
  1005. key = SDLK_UNKNOWN;
  1006. }
  1007. } else if (key >= 0xC0) {
  1008. if (SDL_strlen(name) == 2) {
  1009. int i = 0;
  1010. key = (Uint16)(name[i] & 0x1F) << 6;
  1011. key |= (Uint16)(name[++i] & 0x3F);
  1012. } else {
  1013. key = SDLK_UNKNOWN;
  1014. }
  1015. } else {
  1016. if (SDL_strlen(name) != 1) {
  1017. key = SDLK_UNKNOWN;
  1018. }
  1019. }
  1020. if (key != SDLK_UNKNOWN) {
  1021. if (uppercase) {
  1022. // SDL_Keycode is defined as the unshifted key on the keyboard,
  1023. // but the key name is defined as the letter printed on that key,
  1024. // which is usually the shifted capital letter.
  1025. SDL_Keymap *keymap = SDL_GetCurrentKeymap();
  1026. SDL_Keymod modstate;
  1027. SDL_Scancode scancode = SDL_GetKeymapScancode(keymap, key, &modstate);
  1028. if (scancode != SDL_SCANCODE_UNKNOWN && (modstate & SDL_KMOD_SHIFT)) {
  1029. key = SDL_GetKeymapKeycode(keymap, scancode, SDL_KMOD_NONE);
  1030. }
  1031. }
  1032. return key;
  1033. }
  1034. return SDL_GetKeyFromScancode(SDL_GetScancodeFromName(name), SDL_KMOD_NONE, false);
  1035. }