Identify JavaScript keyboard event properties for any key press. Shows keyCode, key, code, location, and modifier states (Shift, Ctrl, Alt, Meta). Essential for building keyboard shortcuts and accessibility features.
The keyCode property is a legacy integer representing the key pressed. Modern code should use event.key or event.code instead.
key represents the printed character. code represents the physical key position. Use key and code in modern JavaScript.
Use event.key to get the logical value of the key pressed (e.g. 'a', 'Enter', 'ArrowUp'), and event.code for the physical key position (e.g. 'KeyA', 'ShiftLeft'). Avoid the deprecated keyCode property. For cross-platform shortcuts use event.code; for text input handling use event.key.
keyCode and which are deprecated — they return numbers (e.g., Enter=13) and are inconsistent for non-letter keys across keyboard layouts. key is the modern standard, returning meaningful strings (e.g., 'Enter', 'ArrowUp', 'a') independent of keyboard layout — use this. The code property returns the physical key position (e.g., 'KeyA') regardless of input language. New code should use event.key or event.code.