# Understanding keyboard events in JavaScript
When a user presses a key, the browser fires three events:keydown, keypress, and keyup. Each exposes properties with information about the key pressed, but not all are equivalent or recommended.# Key event properties
event.code — The physical key
Returns the identifier of the physical position of the key on the keyboard, using QWERTY nomenclature. For example, the "A" key on an AZERTY keyboard returns KeyQ. Ideal for game controls where position matters, not the character.
event.key — The generated character
Returns the character value generated according to language and active modifiers. Pressing Shift+A returns "A"; without Shift returns "a". For special keys it returns names like "Enter", "Escape", "ArrowUp".
# When to use each property
event.code for game controls (WASD regardless of language) and event.key to detect specific characters or semantic keyboard shortcuts like Ctrl+C. event.which and event.keyCode properties are officially deprecated according to the W3C standard. Although modern browsers continue to support them for compatibility, they should not be used in new code.