Key Codes Tools

Key code tooling: distinguishes keyCode, which and code, explains keydown versus keypress timing, modifier combination order, and when to choose event.key versus event.code under IME and non-Latin layouts.

Keyboard events expose three different value systems, and mixing them breaks shortcuts across layouts.

Approach Comparison

Aspectevent.keyevent.code
MeaningThe key pressed (semantic)The physical position pressed
Affected by layoutYesNo
Affected by IMEYesNo
Example (Ctrl+Z)Varies with languageAlways "KeyZ"
Best forDisplay and text handlingShortcuts, games, forms
Dead keys and combining marksMay misbehaveStable
Number row vs numpadIndistinguishableDistinguishable (Numpad1 vs Digit1)
Browser supportAll modern browsersAll modern browsers

Edge Cases

  • During IME composition (isComposing true) keydown does not fire per character — this is by design, not a bug.
  • event.key depends on the OS keyboard layout, so one physical key returns different characters across languages.
  • The numpad cannot be distinguished under key, but code can (Numpad1 versus Digit1).
  • event.keyCode and which are deprecated and should not appear in new code.

Common Pitfalls

  • Using key for shortcuts, which then fail on non-English layouts such as German or French.
  • Reading input content inside keydown, which always yields the previous value.
  • Intercepting keydown per character during IME composition, breaking candidate window output.
  • Comparing against the deprecated keyCode, which future browsers may drop.

Related Tools