Press keys at the class computer: the teacher’s board lights the physical key (e.code) and the character typed (e.key), your shortcut handler runs on the real…
Shortcuts, command palettes (Ctrl/Cmd+K), game controls (WASD) and forms all sit on KeyboardEvent. Picking the wrong one of key vs code, or preventDefault() in the wrong place, gives you shortcuts that break on other layouts, lose to the browser's own action, or block people's typing.
e.key is what was typed, e.code is which physical key
e.keyCode to detect shortcuts, the numbers differ on another browser keyCode is deprecated, its numbers differ across browsers and layouts (punctuation worst of all, ; can be 186 or 59), and it is 229 for every IME keystroke. Use e.code (position) or e.key (character).e.key === 'a' for a shortcut, it breaks when Shift produces 'A' e.key follows Shift and Caps Lock. For a shortcut, check the consistent e.code === 'KeyA', or normalise with e.key.toLowerCase().e.preventDefault() on keydown, the browser still runs its default. Call it as soon as the shortcut matches, and not on keyup: that is too late. Some browser shortcuts (Ctrl+T, Ctrl+W) cannot be prevented at all.e.key becomes the symbol ('!', '@'…), e.code stays Digit1, Digit2… key knows about Shift, code does not.repeat: true, and a single keyup at the end.preventDefault() runs, so the browser default is cancelled. Try the "Forgot preventDefault" example too.preventDefault() on every keydown, then type No letters go in, beforeinput and input vanish from the board. keydown and keyup are still there.