Skip to content

Instantly share code, notes, and snippets.

@forcepusher
Last active May 15, 2021 15:42
Show Gist options
  • Select an option

  • Save forcepusher/25eb3e100275f95aaa28c666fed4b6d5 to your computer and use it in GitHub Desktop.

Select an option

Save forcepusher/25eb3e100275f95aaa28c666fed4b6d5 to your computer and use it in GitHub Desktop.
Complete KeyboardEvent.code enum.
// Painstakingly copied by hand from https://w3c.github.io/uievents-code/
/**
* To convert from keyboardEvent.code string to KeyboardKey enum use this:
* @example KeyboardKey[keyboardEvent.code as keyof typeof KeyboardKey];
*/
enum KeyboardKey {
// Writing system keys.
Backquote,
Backslash,
BracketLeft,
BracketRight,
Comma,
Digit0,
Digit1,
Digit2,
Digit3,
Digit4,
Digit5,
Digit6,
Digit7,
Digit8,
Digit9,
Equal,
IntlBackslash,
IntlRo,
IntlYen,
KeyA,
KeyB,
KeyC,
KeyD,
KeyE,
KeyF,
KeyG,
KeyH,
KeyI,
KeyJ,
KeyK,
KeyL,
KeyM,
KeyN,
KeyO,
KeyP,
KeyQ,
KeyR,
KeyS,
KeyT,
KeyU,
KeyV,
KeyW,
KeyX,
KeyY,
KeyZ,
Minus,
Period,
Quote,
Semicolon,
Slash,
// Functional keys.
AltLeft,
AltRight,
Backspace,
CapsLock,
ContextMenu,
ControlLeft,
ControlRight,
Enter,
MetaLeft,
MetaRight,
ShiftLeft,
ShiftRight,
Space,
Tab,
// Korean and Jap functional keys.
Convert,
KanaMode,
Lang1,
Lang2,
Lang3,
Lang4,
Lang5,
NonConvert,
// Control pad keys.
Delete,
End,
Help,
Home,
Insert,
PageDown,
PageUp,
// Arrow pad keys.
ArrowDown,
ArrowLeft,
ArrowRight,
ArrowUp,
// Numpad keys
NumLock,
Numpad0,
Numpad1,
Numpad2,
Numpad3,
Numpad4,
Numpad5,
Numpad6,
Numpad7,
Numpad8,
Numpad9,
NumpadAdd,
NumpadBackspace,
NumpadClear,
NumpadClearEntry,
NumpadComma,
NumpadDecimal,
NumpadDivide,
NumpadEnter,
NumpadEqual,
NumpadHash,
NumpadMemoryAdd,
NumpadMemoryClear,
NumpadMemoryRecall,
NumpadMemoryStore,
NumpadMemorySubtract,
NumpadMultiply,
NumpadParenLeft,
NumpadParenRight,
NumpadStar,
NumpadSubtract,
// Function keys.
Escape,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
Fn,
FnLock,
PrintScreen,
ScrollLock,
Pause,
// Media keys.
BrowserBack,
BrowserFavorites,
BrowserForward,
BrowserHome,
BrowserRefresh,
BrowserSearch,
BrowserStop,
Eject,
LaunchApp1,
LaunchApp2,
LaunchMail,
MediaPlayPause,
MediaSelect,
MediaStop,
MediaTrackNext,
MediaTrackPrevious,
Power,
Sleep,
AudioVolumeDown,
AudioVolumeMute,
AudioVolumeUp,
WakeUp,
// Legacy modifier keys.
Hyper,
Super,
Turbo,
// Legacy process control keys.
Abort,
Resume,
Suspend,
// Legacy editing keys.
Again,
Copy,
Cut,
Find,
Open,
Paste,
Props,
Select,
Undo,
// Legacy international keys.
Hiragana,
Katakana,
// Special keys.
Unidentified,
}
export default KeyboardKey;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment