KeyboardInput.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. export var keys = {};
  2. export const KeyCode = {
  3. Escape: "Escape",
  4. F1: "F1",
  5. F2: "F2",
  6. F3: "F3",
  7. F4: "F4",
  8. F5: "F5",
  9. F6: "F6",
  10. F7: "F7",
  11. F8: "F8",
  12. F9: "F9",
  13. F10: "F10",
  14. F11: "F11",
  15. F12: "F12",
  16. Backquote: "Backquote",
  17. Digit1: "Digit1",
  18. Digit2: "Digit2",
  19. Digit3: "Digit3",
  20. Digit4: "Digit4",
  21. Digit5: "Digit5",
  22. Digit6: "Digit6",
  23. Digit7: "Digit7",
  24. Digit8: "Digit8",
  25. Digit9: "Digit9",
  26. Digit0: "Digit0",
  27. Minus: "Minus",
  28. Equal: "Equal",
  29. Backspace: "Backspace",
  30. Tab: "Tab",
  31. KeyQ: "KeyQ",
  32. KeyW: "KeyW",
  33. KeyE: "KeyE",
  34. KeyR: "KeyR",
  35. KeyT: "KeyT",
  36. KeyY: "KeyY",
  37. KeyU: "KeyU",
  38. KeyI: "KeyI",
  39. KeyO: "KeyO",
  40. KeyP: "KeyP",
  41. BracketLeft: "BracketLeft",
  42. BracketRight: "BracketRight",
  43. Backslash: "Backslash",
  44. CapsLock: "CapsLock",
  45. KeyA: "KeyA",
  46. KeyS: "KeyS",
  47. KeyD: "KeyD",
  48. KeyF: "KeyF",
  49. KeyG: "KeyG",
  50. KeyH: "KeyH",
  51. KeyJ: "KeyJ",
  52. KeyK: "KeyK",
  53. KeyL: "KeyL",
  54. Semicolon: "Semicolon",
  55. Quote: "Quote",
  56. Enter: "Enter",
  57. ShiftLeft: "ShiftLeft",
  58. KeyZ: "KeyZ",
  59. KeyX: "KeyX",
  60. KeyC: "KeyC",
  61. KeyV: "KeyV",
  62. KeyB: "KeyB",
  63. KeyN: "KeyN",
  64. KeyM: "KeyM",
  65. Comma: "Comma",
  66. Period: "Period",
  67. Slash: "Slash",
  68. ShiftRight: "ShiftRight",
  69. ControlLeft: "ControlLeft",
  70. AltLeft: "AltLeft",
  71. MetaLeft: "MetaLeft",
  72. Space: "Space",
  73. MetaRight: "MetaRight",
  74. AltRight: "AltRight",
  75. ArrowLeft: "ArrowLeft",
  76. ArrowUp: "ArrowUp",
  77. ArrowDown: "ArrowDown",
  78. ArrowRight: "ArrowRight",
  79. };
  80. window.addEventListener("keydown", onKeyDown);
  81. window.addEventListener("keyup", onKeyUp);
  82. function onKeyDown(event) {
  83. keys[event.code] = true;
  84. }
  85. function onKeyUp(event) {
  86. delete keys[event.code];
  87. }