Toolvist

JS Keycode Tester

Press any key to see its JavaScript keyCode, code and key value instantly. Free online keycode tester for building keyboard shortcuts and handlers.

event.key
—
event.code
—
keyCode
—
which
—
Shift Ctrl Alt Meta

Free JS Keycode Tester

The Keycode Tester shows the key, code, and keyCode of any key you press. Click into the box and type — the event details appear instantly for use in your JavaScript.

The values it reports are the ones a JavaScript Minifier leaves untouched, and the handler logic around them can be compared with the Diff Checker / Text Compare. For the escape sequences that keyboard events produce, the String Escape / Stringify tool shows the literal forms.

How to use the Keycode Tester

  1. 1 Click into the input area to give it focus.
  2. 2 Press any key. The event details appear immediately.
  3. 3 Read three separate values: `key`, `code` and, for legacy purposes, `keyCode`.
  4. 4 Hold modifiers to see how they are reported alongside the key.

Why the legacy value still matters

`keyCode` is deprecated but not gone, and plenty of existing code depends on it. When maintaining or debugging that code, it is useful to see all three values at once, because a handler written against `keyCode` will not behave like one written against `key`.

The values are not interchangeable. `keyCode` reported the same number for an uppercase and lowercase letter, which is why old code needed `shiftKey` checks to distinguish them. `key` reports the distinction directly, which is part of why it replaced the older API.

  • `key` describes the produced character; `code` the physical key.
  • `code` is layout-independent — use it for positional controls.
  • `keyCode` is deprecated and inconsistent between browsers.
  • Some keys are reserved by the browser and cannot be intercepted.

Frequently asked questions

What is the difference between `key` and `code`?

`key` describes what the key produces — the character, taking modifiers and the keyboard layout into account. `code` describes the physical key at a fixed position, independent of layout. So `key` equals `a`, `A` or `á` depending on the layout and the shift state, while `code` is always `KeyA` for that physical key.

Which one should I use in my code?

`code` for anything positional, such as a game where WASD should map to the same physical keys regardless of layout, and `key` for anything about the character produced. `keyCode` is deprecated and should not be used in new code — it is inconsistent between browsers and was never standardised.

Why does my handler not fire for some keys?

Because certain keys are intercepted by the browser or the operating system before the page sees them. Function keys, the browser's own shortcuts, and combinations such as closing a tab cannot be suppressed reliably. Design around those rather than fighting them.

Related Developer Tools

Browse all Developer Tools →