Keyboard Events: key vs code vs keyCode

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…

Why it matters

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.

The key idea

e.key is what was typed, e.code is which physical key

Common mistakes

Try it in this playground