key_mapping_macos.mm 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. /**************************************************************************/
  2. /* key_mapping_macos.mm */
  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_macos.h"
  31. #include "core/templates/hash_map.h"
  32. #include "core/templates/hash_set.h"
  33. #import <Carbon/Carbon.h>
  34. #import <Cocoa/Cocoa.h>
  35. struct HashMapHasherKeys {
  36. static _FORCE_INLINE_ uint32_t hash(const Key p_key) { return hash_fmix32(static_cast<uint32_t>(p_key)); }
  37. static _FORCE_INLINE_ uint32_t hash(const char32_t p_uchar) { return hash_fmix32(p_uchar); }
  38. static _FORCE_INLINE_ uint32_t hash(const unsigned p_key) { return hash_fmix32(p_key); }
  39. };
  40. HashSet<unsigned int> numpad_keys;
  41. HashMap<unsigned int, Key, HashMapHasherKeys> keysym_map;
  42. HashMap<Key, unsigned int, HashMapHasherKeys> keysym_map_inv;
  43. HashMap<Key, char32_t, HashMapHasherKeys> keycode_map;
  44. HashMap<unsigned int, KeyLocation, HashMapHasherKeys> location_map;
  45. void KeyMappingMacOS::initialize() {
  46. numpad_keys.insert(0x41); //kVK_ANSI_KeypadDecimal
  47. numpad_keys.insert(0x43); //kVK_ANSI_KeypadMultiply
  48. numpad_keys.insert(0x45); //kVK_ANSI_KeypadPlus
  49. numpad_keys.insert(0x47); //kVK_ANSI_KeypadClear
  50. numpad_keys.insert(0x4b); //kVK_ANSI_KeypadDivide
  51. numpad_keys.insert(0x4c); //kVK_ANSI_KeypadEnter
  52. numpad_keys.insert(0x4e); //kVK_ANSI_KeypadMinus
  53. numpad_keys.insert(0x51); //kVK_ANSI_KeypadEquals
  54. numpad_keys.insert(0x52); //kVK_ANSI_Keypad0
  55. numpad_keys.insert(0x53); //kVK_ANSI_Keypad1
  56. numpad_keys.insert(0x54); //kVK_ANSI_Keypad2
  57. numpad_keys.insert(0x55); //kVK_ANSI_Keypad3
  58. numpad_keys.insert(0x56); //kVK_ANSI_Keypad4
  59. numpad_keys.insert(0x57); //kVK_ANSI_Keypad5
  60. numpad_keys.insert(0x58); //kVK_ANSI_Keypad6
  61. numpad_keys.insert(0x59); //kVK_ANSI_Keypad7
  62. numpad_keys.insert(0x5b); //kVK_ANSI_Keypad8
  63. numpad_keys.insert(0x5c); //kVK_ANSI_Keypad9
  64. numpad_keys.insert(0x5f); //kVK_JIS_KeypadComma
  65. keysym_map[0x00] = Key::A;
  66. keysym_map[0x01] = Key::S;
  67. keysym_map[0x02] = Key::D;
  68. keysym_map[0x03] = Key::F;
  69. keysym_map[0x04] = Key::H;
  70. keysym_map[0x05] = Key::G;
  71. keysym_map[0x06] = Key::Z;
  72. keysym_map[0x07] = Key::X;
  73. keysym_map[0x08] = Key::C;
  74. keysym_map[0x09] = Key::V;
  75. keysym_map[0x0a] = Key::SECTION;
  76. keysym_map[0x0b] = Key::B;
  77. keysym_map[0x0c] = Key::Q;
  78. keysym_map[0x0d] = Key::W;
  79. keysym_map[0x0e] = Key::E;
  80. keysym_map[0x0f] = Key::R;
  81. keysym_map[0x10] = Key::Y;
  82. keysym_map[0x11] = Key::T;
  83. keysym_map[0x12] = Key::KEY_1;
  84. keysym_map[0x13] = Key::KEY_2;
  85. keysym_map[0x14] = Key::KEY_3;
  86. keysym_map[0x15] = Key::KEY_4;
  87. keysym_map[0x16] = Key::KEY_6;
  88. keysym_map[0x17] = Key::KEY_5;
  89. keysym_map[0x18] = Key::EQUAL;
  90. keysym_map[0x19] = Key::KEY_9;
  91. keysym_map[0x1a] = Key::KEY_7;
  92. keysym_map[0x1b] = Key::MINUS;
  93. keysym_map[0x1c] = Key::KEY_8;
  94. keysym_map[0x1d] = Key::KEY_0;
  95. keysym_map[0x1e] = Key::BRACKETRIGHT;
  96. keysym_map[0x1f] = Key::O;
  97. keysym_map[0x20] = Key::U;
  98. keysym_map[0x21] = Key::BRACKETLEFT;
  99. keysym_map[0x22] = Key::I;
  100. keysym_map[0x23] = Key::P;
  101. keysym_map[0x24] = Key::ENTER;
  102. keysym_map[0x25] = Key::L;
  103. keysym_map[0x26] = Key::J;
  104. keysym_map[0x27] = Key::APOSTROPHE;
  105. keysym_map[0x28] = Key::K;
  106. keysym_map[0x29] = Key::SEMICOLON;
  107. keysym_map[0x2a] = Key::BACKSLASH;
  108. keysym_map[0x2b] = Key::COMMA;
  109. keysym_map[0x2c] = Key::SLASH;
  110. keysym_map[0x2d] = Key::N;
  111. keysym_map[0x2e] = Key::M;
  112. keysym_map[0x2f] = Key::PERIOD;
  113. keysym_map[0x30] = Key::TAB;
  114. keysym_map[0x31] = Key::SPACE;
  115. keysym_map[0x32] = Key::QUOTELEFT;
  116. keysym_map[0x33] = Key::BACKSPACE;
  117. keysym_map[0x35] = Key::ESCAPE;
  118. keysym_map[0x36] = Key::META;
  119. keysym_map[0x37] = Key::META;
  120. keysym_map[0x38] = Key::SHIFT;
  121. keysym_map[0x39] = Key::CAPSLOCK;
  122. keysym_map[0x3a] = Key::ALT;
  123. keysym_map[0x3b] = Key::CTRL;
  124. keysym_map[0x3c] = Key::SHIFT;
  125. keysym_map[0x3d] = Key::ALT;
  126. keysym_map[0x3e] = Key::CTRL;
  127. keysym_map[0x40] = Key::F17;
  128. keysym_map[0x41] = Key::KP_PERIOD;
  129. keysym_map[0x43] = Key::KP_MULTIPLY;
  130. keysym_map[0x45] = Key::KP_ADD;
  131. keysym_map[0x47] = Key::NUMLOCK;
  132. keysym_map[0x48] = Key::VOLUMEUP;
  133. keysym_map[0x49] = Key::VOLUMEDOWN;
  134. keysym_map[0x4a] = Key::VOLUMEMUTE;
  135. keysym_map[0x4b] = Key::KP_DIVIDE;
  136. keysym_map[0x4c] = Key::KP_ENTER;
  137. keysym_map[0x4e] = Key::KP_SUBTRACT;
  138. keysym_map[0x4f] = Key::F18;
  139. keysym_map[0x50] = Key::F19;
  140. keysym_map[0x51] = Key::EQUAL;
  141. keysym_map[0x52] = Key::KP_0;
  142. keysym_map[0x53] = Key::KP_1;
  143. keysym_map[0x54] = Key::KP_2;
  144. keysym_map[0x55] = Key::KP_3;
  145. keysym_map[0x56] = Key::KP_4;
  146. keysym_map[0x57] = Key::KP_5;
  147. keysym_map[0x58] = Key::KP_6;
  148. keysym_map[0x59] = Key::KP_7;
  149. keysym_map[0x5a] = Key::F20;
  150. keysym_map[0x5b] = Key::KP_8;
  151. keysym_map[0x5c] = Key::KP_9;
  152. keysym_map[0x5d] = Key::YEN;
  153. keysym_map[0x5e] = Key::UNDERSCORE;
  154. keysym_map[0x5f] = Key::COMMA;
  155. keysym_map[0x60] = Key::F5;
  156. keysym_map[0x61] = Key::F6;
  157. keysym_map[0x62] = Key::F7;
  158. keysym_map[0x63] = Key::F3;
  159. keysym_map[0x64] = Key::F8;
  160. keysym_map[0x65] = Key::F9;
  161. keysym_map[0x66] = Key::JIS_EISU;
  162. keysym_map[0x67] = Key::F11;
  163. keysym_map[0x68] = Key::JIS_KANA;
  164. keysym_map[0x69] = Key::F13;
  165. keysym_map[0x6a] = Key::F16;
  166. keysym_map[0x6b] = Key::F14;
  167. keysym_map[0x6d] = Key::F10;
  168. keysym_map[0x6e] = Key::MENU;
  169. keysym_map[0x6f] = Key::F12;
  170. keysym_map[0x71] = Key::F15;
  171. keysym_map[0x72] = Key::INSERT;
  172. keysym_map[0x73] = Key::HOME;
  173. keysym_map[0x74] = Key::PAGEUP;
  174. keysym_map[0x75] = Key::KEY_DELETE;
  175. keysym_map[0x76] = Key::F4;
  176. keysym_map[0x77] = Key::END;
  177. keysym_map[0x78] = Key::F2;
  178. keysym_map[0x79] = Key::PAGEDOWN;
  179. keysym_map[0x7a] = Key::F1;
  180. keysym_map[0x7b] = Key::LEFT;
  181. keysym_map[0x7c] = Key::RIGHT;
  182. keysym_map[0x7d] = Key::DOWN;
  183. keysym_map[0x7e] = Key::UP;
  184. for (const KeyValue<unsigned int, Key> &E : keysym_map) {
  185. keysym_map_inv[E.value] = E.key;
  186. }
  187. keycode_map[Key::ESCAPE] = 0x001B;
  188. keycode_map[Key::TAB] = 0x0009;
  189. keycode_map[Key::BACKTAB] = 0x007F;
  190. keycode_map[Key::BACKSPACE] = 0x0008;
  191. keycode_map[Key::ENTER] = 0x000D;
  192. keycode_map[Key::INSERT] = NSInsertFunctionKey;
  193. keycode_map[Key::KEY_DELETE] = 0x007F;
  194. keycode_map[Key::PAUSE] = NSPauseFunctionKey;
  195. keycode_map[Key::PRINT] = NSPrintScreenFunctionKey;
  196. keycode_map[Key::SYSREQ] = NSSysReqFunctionKey;
  197. keycode_map[Key::CLEAR] = NSClearLineFunctionKey;
  198. keycode_map[Key::HOME] = 0x2196;
  199. keycode_map[Key::END] = 0x2198;
  200. keycode_map[Key::LEFT] = 0x001C;
  201. keycode_map[Key::UP] = 0x001E;
  202. keycode_map[Key::RIGHT] = 0x001D;
  203. keycode_map[Key::DOWN] = 0x001F;
  204. keycode_map[Key::PAGEUP] = 0x21DE;
  205. keycode_map[Key::PAGEDOWN] = 0x21DF;
  206. keycode_map[Key::NUMLOCK] = NSClearLineFunctionKey;
  207. keycode_map[Key::SCROLLLOCK] = NSScrollLockFunctionKey;
  208. keycode_map[Key::F1] = NSF1FunctionKey;
  209. keycode_map[Key::F2] = NSF2FunctionKey;
  210. keycode_map[Key::F3] = NSF3FunctionKey;
  211. keycode_map[Key::F4] = NSF4FunctionKey;
  212. keycode_map[Key::F5] = NSF5FunctionKey;
  213. keycode_map[Key::F6] = NSF6FunctionKey;
  214. keycode_map[Key::F7] = NSF7FunctionKey;
  215. keycode_map[Key::F8] = NSF8FunctionKey;
  216. keycode_map[Key::F9] = NSF9FunctionKey;
  217. keycode_map[Key::F10] = NSF10FunctionKey;
  218. keycode_map[Key::F11] = NSF11FunctionKey;
  219. keycode_map[Key::F12] = NSF12FunctionKey;
  220. keycode_map[Key::F13] = NSF13FunctionKey;
  221. keycode_map[Key::F14] = NSF14FunctionKey;
  222. keycode_map[Key::F15] = NSF15FunctionKey;
  223. keycode_map[Key::F16] = NSF16FunctionKey;
  224. keycode_map[Key::F17] = NSF17FunctionKey;
  225. keycode_map[Key::F18] = NSF18FunctionKey;
  226. keycode_map[Key::F19] = NSF19FunctionKey;
  227. keycode_map[Key::F20] = NSF20FunctionKey;
  228. keycode_map[Key::F21] = NSF21FunctionKey;
  229. keycode_map[Key::F22] = NSF22FunctionKey;
  230. keycode_map[Key::F23] = NSF23FunctionKey;
  231. keycode_map[Key::F24] = NSF24FunctionKey;
  232. keycode_map[Key::F25] = NSF25FunctionKey;
  233. keycode_map[Key::F26] = NSF26FunctionKey;
  234. keycode_map[Key::F27] = NSF27FunctionKey;
  235. keycode_map[Key::F28] = NSF28FunctionKey;
  236. keycode_map[Key::F29] = NSF29FunctionKey;
  237. keycode_map[Key::F30] = NSF30FunctionKey;
  238. keycode_map[Key::F31] = NSF31FunctionKey;
  239. keycode_map[Key::F32] = NSF32FunctionKey;
  240. keycode_map[Key::F33] = NSF33FunctionKey;
  241. keycode_map[Key::F34] = NSF34FunctionKey;
  242. keycode_map[Key::F35] = NSF35FunctionKey;
  243. keycode_map[Key::MENU] = NSMenuFunctionKey;
  244. keycode_map[Key::HELP] = NSHelpFunctionKey;
  245. keycode_map[Key::STOP] = NSStopFunctionKey;
  246. keycode_map[Key::LAUNCH0] = NSUserFunctionKey;
  247. keycode_map[Key::SPACE] = 0x0020;
  248. keycode_map[Key::EXCLAM] = '!';
  249. keycode_map[Key::QUOTEDBL] = '\"';
  250. keycode_map[Key::NUMBERSIGN] = '#';
  251. keycode_map[Key::DOLLAR] = '$';
  252. keycode_map[Key::PERCENT] = '\%';
  253. keycode_map[Key::AMPERSAND] = '&';
  254. keycode_map[Key::APOSTROPHE] = '\'';
  255. keycode_map[Key::PARENLEFT] = '(';
  256. keycode_map[Key::PARENRIGHT] = ')';
  257. keycode_map[Key::ASTERISK] = '*';
  258. keycode_map[Key::PLUS] = '+';
  259. keycode_map[Key::COMMA] = ',';
  260. keycode_map[Key::MINUS] = '-';
  261. keycode_map[Key::PERIOD] = '.';
  262. keycode_map[Key::SLASH] = '/';
  263. keycode_map[Key::KEY_0] = '0';
  264. keycode_map[Key::KEY_1] = '1';
  265. keycode_map[Key::KEY_2] = '2';
  266. keycode_map[Key::KEY_3] = '3';
  267. keycode_map[Key::KEY_4] = '4';
  268. keycode_map[Key::KEY_5] = '5';
  269. keycode_map[Key::KEY_6] = '6';
  270. keycode_map[Key::KEY_7] = '7';
  271. keycode_map[Key::KEY_8] = '8';
  272. keycode_map[Key::KEY_9] = '9';
  273. keycode_map[Key::COLON] = ':';
  274. keycode_map[Key::SEMICOLON] = ';';
  275. keycode_map[Key::LESS] = '<';
  276. keycode_map[Key::EQUAL] = '=';
  277. keycode_map[Key::GREATER] = '>';
  278. keycode_map[Key::QUESTION] = '?';
  279. keycode_map[Key::AT] = '@';
  280. keycode_map[Key::A] = 'a';
  281. keycode_map[Key::B] = 'b';
  282. keycode_map[Key::C] = 'c';
  283. keycode_map[Key::D] = 'd';
  284. keycode_map[Key::E] = 'e';
  285. keycode_map[Key::F] = 'f';
  286. keycode_map[Key::G] = 'g';
  287. keycode_map[Key::H] = 'h';
  288. keycode_map[Key::I] = 'i';
  289. keycode_map[Key::J] = 'j';
  290. keycode_map[Key::K] = 'k';
  291. keycode_map[Key::L] = 'l';
  292. keycode_map[Key::M] = 'm';
  293. keycode_map[Key::N] = 'n';
  294. keycode_map[Key::O] = 'o';
  295. keycode_map[Key::P] = 'p';
  296. keycode_map[Key::Q] = 'q';
  297. keycode_map[Key::R] = 'r';
  298. keycode_map[Key::S] = 's';
  299. keycode_map[Key::T] = 't';
  300. keycode_map[Key::U] = 'u';
  301. keycode_map[Key::V] = 'v';
  302. keycode_map[Key::W] = 'w';
  303. keycode_map[Key::X] = 'x';
  304. keycode_map[Key::Y] = 'y';
  305. keycode_map[Key::Z] = 'z';
  306. keycode_map[Key::BRACKETLEFT] = '[';
  307. keycode_map[Key::BACKSLASH] = '\\';
  308. keycode_map[Key::BRACKETRIGHT] = ']';
  309. keycode_map[Key::ASCIICIRCUM] = '^';
  310. keycode_map[Key::UNDERSCORE] = '_';
  311. keycode_map[Key::QUOTELEFT] = '`';
  312. keycode_map[Key::BRACELEFT] = '{';
  313. keycode_map[Key::BAR] = '|';
  314. keycode_map[Key::BRACERIGHT] = '}';
  315. keycode_map[Key::ASCIITILDE] = '~';
  316. // Keysym -> physical location.
  317. // Ctrl.
  318. location_map[0x3b] = KeyLocation::LEFT;
  319. location_map[0x3e] = KeyLocation::RIGHT;
  320. // Shift.
  321. location_map[0x38] = KeyLocation::LEFT;
  322. location_map[0x3c] = KeyLocation::RIGHT;
  323. // Alt/Option.
  324. location_map[0x3a] = KeyLocation::LEFT;
  325. location_map[0x3d] = KeyLocation::RIGHT;
  326. // Meta/Command (yes, right < left).
  327. location_map[0x36] = KeyLocation::RIGHT;
  328. location_map[0x37] = KeyLocation::LEFT;
  329. }
  330. bool KeyMappingMacOS::is_numpad_key(unsigned int p_key) {
  331. return numpad_keys.has(p_key);
  332. }
  333. // Translates a macOS keycode to a Godot keycode.
  334. Key KeyMappingMacOS::translate_key(unsigned int p_key) {
  335. const Key *key = keysym_map.getptr(p_key);
  336. if (key) {
  337. return *key;
  338. }
  339. return Key::NONE;
  340. }
  341. // Translates a Godot keycode back to a macOS keycode.
  342. unsigned int KeyMappingMacOS::unmap_key(Key p_key) {
  343. const unsigned int *key = keysym_map_inv.getptr(p_key);
  344. if (key) {
  345. return *key;
  346. }
  347. return 127;
  348. }
  349. // Remap key according to current keyboard layout.
  350. Key KeyMappingMacOS::remap_key(unsigned int p_key, unsigned int p_state, bool p_unicode) {
  351. if (is_numpad_key(p_key)) {
  352. return translate_key(p_key);
  353. }
  354. TISInputSourceRef current_keyboard = TISCopyCurrentKeyboardInputSource();
  355. if (!current_keyboard) {
  356. return translate_key(p_key);
  357. }
  358. CFDataRef layout_data = (CFDataRef)TISGetInputSourceProperty(current_keyboard, kTISPropertyUnicodeKeyLayoutData);
  359. if (!layout_data) {
  360. return translate_key(p_key);
  361. }
  362. const UCKeyboardLayout *keyboard_layout = (const UCKeyboardLayout *)CFDataGetBytePtr(layout_data);
  363. String keysym;
  364. UInt32 keys_down = 0;
  365. UniChar chars[256] = {};
  366. UniCharCount real_length = 0;
  367. OSStatus err = UCKeyTranslate(keyboard_layout,
  368. p_key,
  369. kUCKeyActionDisplay,
  370. (p_unicode) ? 0 : (p_state >> 8) & 0xFF,
  371. LMGetKbdType(),
  372. kUCKeyTranslateNoDeadKeysBit,
  373. &keys_down,
  374. sizeof(chars) / sizeof(chars[0]),
  375. &real_length,
  376. chars);
  377. if (err != noErr) {
  378. return translate_key(p_key);
  379. }
  380. keysym = String::utf16((char16_t *)chars, real_length);
  381. if (keysym.is_empty()) {
  382. return translate_key(p_key);
  383. }
  384. char32_t c = keysym[0];
  385. if (p_unicode) {
  386. return fix_key_label(c, translate_key(p_key));
  387. } else {
  388. return fix_keycode(c, translate_key(p_key));
  389. }
  390. }
  391. // Translates a macOS keycode to a Godot key location.
  392. KeyLocation KeyMappingMacOS::translate_location(unsigned int p_key) {
  393. const KeyLocation *location = location_map.getptr(p_key);
  394. if (location) {
  395. return *location;
  396. }
  397. return KeyLocation::UNSPECIFIED;
  398. }
  399. String KeyMappingMacOS::keycode_get_native_string(Key p_keycode) {
  400. const char32_t *key = keycode_map.getptr(p_keycode);
  401. if (key) {
  402. return String::chr(*key);
  403. }
  404. return String();
  405. }
  406. unsigned int KeyMappingMacOS::keycode_get_native_mask(Key p_keycode) {
  407. unsigned int mask = 0;
  408. if ((p_keycode & KeyModifierMask::CTRL) != Key::NONE) {
  409. mask |= NSEventModifierFlagControl;
  410. }
  411. if ((p_keycode & KeyModifierMask::ALT) != Key::NONE) {
  412. mask |= NSEventModifierFlagOption;
  413. }
  414. if ((p_keycode & KeyModifierMask::SHIFT) != Key::NONE) {
  415. mask |= NSEventModifierFlagShift;
  416. }
  417. if ((p_keycode & KeyModifierMask::META) != Key::NONE) {
  418. mask |= NSEventModifierFlagCommand;
  419. }
  420. if ((p_keycode & KeyModifierMask::KPAD) != Key::NONE) {
  421. mask |= NSEventModifierFlagNumericPad;
  422. }
  423. return mask;
  424. }