Practical guide and verification
Use key and code for different questions
KeyboardEvent.key describes the interpreted key value while KeyboardEvent.code describes the physical key position. Layout changes can alter key without changing code, which matters for shortcuts, games, and international keyboards.
Read location for duplicated keys
Keys such as Shift, Control, Enter, and numeric keypad keys can have location information that distinguishes left, right, or numpad positions. Do not rely only on the visible key label when physical placement matters.
Repeat events are not new physical presses
Holding a key can produce repeated keydown events after the operating system’s repeat delay. Check the repeat flag before counting every event as a separate physical action.
Legacy numeric keyCode is compatibility evidence only
Modern code should prefer key and code. Numeric keyCode values are retained by some browsers for older software but are deprecated and can be inconsistent across layouts or event types.
Browser events cannot certify keyboard hardware
The tester shows events delivered to the page. Firmware, USB polling, OS remapping, accessibility settings, browser shortcuts, and focus rules can all affect what arrives, so use the result as browser-level diagnostic evidence.