PulsePick Tools
Developer Tools

JavaScript Keycode Finder

Press any key to see its event.key, event.code, keyCode, location and active modifier keys in real time.

Press any key on your keyboard

Note: event.keyCode is deprecated. Use event.key for characters and event.code for physical key positions.

100% private

This tool runs entirely in your browser. Nothing you type is uploaded, logged or stored.

Handling Keyboard Events in Modern JavaScript

Keyboard events expose several overlapping properties, and choosing the right one prevents most cross-platform bugs. `event.key` returns the character or named key produced — 'a', 'A', 'Enter', 'ArrowLeft' — and respects the user's keyboard layout and modifier state. `event.code` returns the physical key position — 'KeyA', 'Enter', 'ArrowLeft' — regardless of layout, which is what games and positional shortcuts need. `event.keyCode` is a deprecated numeric identifier kept only for legacy compatibility; new code should not read it.

Pick by intent: use `event.key` when you care what the user typed, and `event.code` when you care which physical key was pressed. A WASD movement scheme built on `event.key` breaks entirely on an AZERTY keyboard, while a shortcut checking `event.code === 'KeyS'` with the meta key held works everywhere. The `location` property distinguishes left and right modifiers and numeric-keypad keys.

Three practical rules round it out. Listen for `keydown` for shortcuts and navigation, since it repeats while held and fires before the character is inserted; use `keyup` for one-shot toggles. Call `preventDefault()` only for combinations you genuinely handle — hijacking browser or accessibility shortcuts is a common accessibility failure. And never rely on keyboard events alone for text input handling: input method editors, autofill and mobile virtual keyboards may fire no key events at all, so bind to the `input` event for value changes.

Frequently asked questions

Use event.key when you need the character produced and event.code when you need the physical key position, such as WASD controls that must work on any layout.