keyUtils.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. "use strict";
  2. /**
  3. * Copyright 2023 Google LLC.
  4. * Copyright (c) Microsoft Corporation.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. Object.defineProperty(exports, "__esModule", { value: true });
  19. exports.getKeyLocation = exports.getKeyCode = exports.getNormalizedKey = void 0;
  20. function getNormalizedKey(value) {
  21. switch (value) {
  22. case '\uE000':
  23. return 'Unidentified';
  24. case '\uE001':
  25. return 'Cancel';
  26. case '\uE002':
  27. return 'Help';
  28. case '\uE003':
  29. return 'Backspace';
  30. case '\uE004':
  31. return 'Tab';
  32. case '\uE005':
  33. return 'Clear';
  34. case '\uE006':
  35. return 'Return';
  36. case '\uE007':
  37. return 'Enter';
  38. case '\uE008':
  39. return 'Shift';
  40. case '\uE009':
  41. return 'Control';
  42. case '\uE00A':
  43. return 'Alt';
  44. case '\uE00B':
  45. return 'Pause';
  46. case '\uE00C':
  47. return 'Escape';
  48. case '\uE00D':
  49. return ' ';
  50. case '\uE00E':
  51. return 'PageUp';
  52. case '\uE00F':
  53. return 'PageDown';
  54. case '\uE010':
  55. return 'End';
  56. case '\uE011':
  57. return 'Home';
  58. case '\uE012':
  59. return 'ArrowLeft';
  60. case '\uE013':
  61. return 'ArrowUp';
  62. case '\uE014':
  63. return 'ArrowRight';
  64. case '\uE015':
  65. return 'ArrowDown';
  66. case '\uE016':
  67. return 'Insert';
  68. case '\uE017':
  69. return 'Delete';
  70. case '\uE018':
  71. return ';';
  72. case '\uE019':
  73. return '=';
  74. case '\uE01A':
  75. return '0';
  76. case '\uE01B':
  77. return '1';
  78. case '\uE01C':
  79. return '2';
  80. case '\uE01D':
  81. return '3';
  82. case '\uE01E':
  83. return '4';
  84. case '\uE01F':
  85. return '5';
  86. case '\uE020':
  87. return '6';
  88. case '\uE021':
  89. return '7';
  90. case '\uE022':
  91. return '8';
  92. case '\uE023':
  93. return '9';
  94. case '\uE024':
  95. return '*';
  96. case '\uE025':
  97. return '+';
  98. case '\uE026':
  99. return ',';
  100. case '\uE027':
  101. return '-';
  102. case '\uE028':
  103. return '.';
  104. case '\uE029':
  105. return '/';
  106. case '\uE031':
  107. return 'F1';
  108. case '\uE032':
  109. return 'F2';
  110. case '\uE033':
  111. return 'F3';
  112. case '\uE034':
  113. return 'F4';
  114. case '\uE035':
  115. return 'F5';
  116. case '\uE036':
  117. return 'F6';
  118. case '\uE037':
  119. return 'F7';
  120. case '\uE038':
  121. return 'F8';
  122. case '\uE039':
  123. return 'F9';
  124. case '\uE03A':
  125. return 'F10';
  126. case '\uE03B':
  127. return 'F11';
  128. case '\uE03C':
  129. return 'F12';
  130. case '\uE03D':
  131. return 'Meta';
  132. case '\uE040':
  133. return 'ZenkakuHankaku';
  134. case '\uE050':
  135. return 'Shift';
  136. case '\uE051':
  137. return 'Control';
  138. case '\uE052':
  139. return 'Alt';
  140. case '\uE053':
  141. return 'Meta';
  142. case '\uE054':
  143. return 'PageUp';
  144. case '\uE055':
  145. return 'PageDown';
  146. case '\uE056':
  147. return 'End';
  148. case '\uE057':
  149. return 'Home';
  150. case '\uE058':
  151. return 'ArrowLeft';
  152. case '\uE059':
  153. return 'ArrowUp';
  154. case '\uE05A':
  155. return 'ArrowRight';
  156. case '\uE05B':
  157. return 'ArrowDown';
  158. case '\uE05C':
  159. return 'Insert';
  160. case '\uE05D':
  161. return 'Delete';
  162. default:
  163. return value;
  164. }
  165. }
  166. exports.getNormalizedKey = getNormalizedKey;
  167. function getKeyCode(key) {
  168. switch (key) {
  169. case '`':
  170. case '~':
  171. return 'Backquote';
  172. case '\\':
  173. case '|':
  174. return 'Backslash';
  175. case '\uE003':
  176. return 'Backspace';
  177. case '[':
  178. case '{':
  179. return 'BracketLeft';
  180. case ']':
  181. case '}':
  182. return 'BracketRight';
  183. case ',':
  184. case '<':
  185. return 'Comma';
  186. case '0':
  187. case ')':
  188. return 'Digit0';
  189. case '1':
  190. case '!':
  191. return 'Digit1';
  192. case '2':
  193. case '@':
  194. return 'Digit2';
  195. case '3':
  196. case '#':
  197. return 'Digit3';
  198. case '4':
  199. case '$':
  200. return 'Digit4';
  201. case '5':
  202. case '%':
  203. return 'Digit5';
  204. case '6':
  205. case '^':
  206. return 'Digit6';
  207. case '7':
  208. case '&':
  209. return 'Digit7';
  210. case '8':
  211. case '*':
  212. return 'Digit8';
  213. case '9':
  214. case '(':
  215. return 'Digit9';
  216. case '=':
  217. case '+':
  218. return 'Equal';
  219. case 'a':
  220. case 'A':
  221. return 'KeyA';
  222. case 'b':
  223. case 'B':
  224. return 'KeyB';
  225. case 'c':
  226. case 'C':
  227. return 'KeyC';
  228. case 'd':
  229. case 'D':
  230. return 'KeyD';
  231. case 'e':
  232. case 'E':
  233. return 'KeyE';
  234. case 'f':
  235. case 'F':
  236. return 'KeyF';
  237. case 'g':
  238. case 'G':
  239. return 'KeyG';
  240. case 'h':
  241. case 'H':
  242. return 'KeyH';
  243. case 'i':
  244. case 'I':
  245. return 'KeyI';
  246. case 'j':
  247. case 'J':
  248. return 'KeyJ';
  249. case 'k':
  250. case 'K':
  251. return 'KeyK';
  252. case 'l':
  253. case 'L':
  254. return 'KeyL';
  255. case 'm':
  256. case 'M':
  257. return 'KeyM';
  258. case 'n':
  259. case 'N':
  260. return 'KeyN';
  261. case 'o':
  262. case 'O':
  263. return 'KeyO';
  264. case 'p':
  265. case 'P':
  266. return 'KeyP';
  267. case 'q':
  268. case 'Q':
  269. return 'KeyQ';
  270. case 'r':
  271. case 'R':
  272. return 'KeyR';
  273. case 's':
  274. case 'S':
  275. return 'KeyS';
  276. case 't':
  277. case 'T':
  278. return 'KeyT';
  279. case 'u':
  280. case 'U':
  281. return 'KeyU';
  282. case 'v':
  283. case 'V':
  284. return 'KeyV';
  285. case 'w':
  286. case 'W':
  287. return 'KeyW';
  288. case 'x':
  289. case 'X':
  290. return 'KeyX';
  291. case 'y':
  292. case 'Y':
  293. return 'KeyY';
  294. case 'z':
  295. case 'Z':
  296. return 'KeyZ';
  297. case '-':
  298. case '_':
  299. return 'Minus';
  300. case '.':
  301. return 'Period';
  302. case "'":
  303. case '"':
  304. return 'Quote';
  305. case ';':
  306. case ':':
  307. return 'Semicolon';
  308. case '/':
  309. case '?':
  310. return 'Slash';
  311. case '\uE00A':
  312. return 'AltLeft';
  313. case '\uE052':
  314. return 'AltRight';
  315. case '\uE009':
  316. return 'ControlLeft';
  317. case '\uE051':
  318. return 'ControlRight';
  319. case '\uE006':
  320. return 'Enter';
  321. case '\uE03D':
  322. return 'MetaLeft';
  323. case '\uE053':
  324. return 'MetaRight';
  325. case '\uE008':
  326. return 'ShiftLeft';
  327. case '\uE050':
  328. return 'ShiftRight';
  329. case ' ':
  330. case '\uE00D':
  331. return 'Space';
  332. case '\uE004':
  333. return 'Tab';
  334. case '\uE017':
  335. return 'Delete';
  336. case '\uE010':
  337. return 'End';
  338. case '\uE002':
  339. return 'Help';
  340. case '\uE011':
  341. return 'Home';
  342. case '\uE016':
  343. return 'Insert';
  344. case '\uE00F':
  345. return 'PageDown';
  346. case '\uE00E':
  347. return 'PageUp';
  348. case '\uE015':
  349. return 'ArrowDown';
  350. case '\uE012':
  351. return 'ArrowLeft';
  352. case '\uE014':
  353. return 'ArrowRight';
  354. case '\uE013':
  355. return 'ArrowUp';
  356. case '\uE00C':
  357. return 'Escape';
  358. case '\uE031':
  359. return 'F1';
  360. case '\uE032':
  361. return 'F2';
  362. case '\uE033':
  363. return 'F3';
  364. case '\uE034':
  365. return 'F4';
  366. case '\uE035':
  367. return 'F5';
  368. case '\uE036':
  369. return 'F6';
  370. case '\uE037':
  371. return 'F7';
  372. case '\uE038':
  373. return 'F8';
  374. case '\uE039':
  375. return 'F9';
  376. case '\uE03A':
  377. return 'F10';
  378. case '\uE03B':
  379. return 'F11';
  380. case '\uE03C':
  381. return 'F12';
  382. case '\uE01A':
  383. case '\uE05C':
  384. return 'Numpad0';
  385. case '\uE01B':
  386. case '\uE056':
  387. return 'Numpad1';
  388. case '\uE01C':
  389. case '\uE05B':
  390. return 'Numpad2';
  391. case '\uE01D':
  392. case '\uE055':
  393. return 'Numpad3';
  394. case '\uE01E':
  395. case '\uE058':
  396. return 'Numpad4';
  397. case '\uE01F':
  398. return 'Numpad5';
  399. case '\uE020':
  400. case '\uE05A':
  401. return 'Numpad6';
  402. case '\uE021':
  403. case '\uE057':
  404. return 'Numpad7';
  405. case '\uE022':
  406. case '\uE059':
  407. return 'Numpad8';
  408. case '\uE023':
  409. case '\uE054':
  410. return 'Numpad9';
  411. case '\uE025':
  412. return 'NumpadAdd';
  413. case '\uE026':
  414. return 'NumpadComma';
  415. case '\uE028':
  416. case '\uE05D':
  417. return 'NumpadDecimal';
  418. case '\uE029':
  419. return 'NumpadDivide';
  420. case '\uE007':
  421. return 'NumpadEnter';
  422. case '\uE024':
  423. return 'NumpadMultiply';
  424. case '\uE027':
  425. return 'NumpadSubtract';
  426. default:
  427. return;
  428. }
  429. }
  430. exports.getKeyCode = getKeyCode;
  431. function getKeyLocation(key) {
  432. switch (key) {
  433. case '\uE007':
  434. case '\uE008':
  435. case '\uE009':
  436. case '\uE00A':
  437. case '\uE03D':
  438. return 1;
  439. case '\uE01A':
  440. case '\uE01B':
  441. case '\uE01C':
  442. case '\uE01D':
  443. case '\uE01E':
  444. case '\uE01F':
  445. case '\uE020':
  446. case '\uE021':
  447. case '\uE022':
  448. case '\uE023':
  449. case '\uE024':
  450. case '\uE025':
  451. case '\uE026':
  452. case '\uE027':
  453. case '\uE028':
  454. case '\uE029':
  455. case '\uE054':
  456. case '\uE055':
  457. case '\uE056':
  458. case '\uE057':
  459. case '\uE058':
  460. case '\uE059':
  461. case '\uE05A':
  462. case '\uE05B':
  463. case '\uE05C':
  464. case '\uE05D':
  465. return 3;
  466. case '\uE050':
  467. case '\uE051':
  468. case '\uE052':
  469. case '\uE053':
  470. return 2;
  471. default:
  472. return 0;
  473. }
  474. }
  475. exports.getKeyLocation = getKeyLocation;
  476. //# sourceMappingURL=keyUtils.js.map