JavaScript Keycode Finder – event.key and event.code

Press any key on your keyboard to see exactly what JavaScript receives: key, code, keyCode and more.

FreeNo sign-upPrivate — runs in your browser
event.keyCodePress any keyClick here first on a phone, then type
event.key—
event.code—
event.keyCode / which—
event.location—
Modifiers—
event.repeat—

Code snippet

// Press a key to see a snippet

History

keycodekeyCodeModifiers

How to use the Keycode Finder

  1. Press a keyPress any key or key combination. On a phone, tap the dark box first to bring up the keyboard focus.
  2. Read the valuesSee event.key (the character or key name), event.code (the physical key), the old keyCode and which numbers, the location (left, right, numpad) and the modifier keys held.
  3. Copy the snippetCopy a ready-made keydown listener for that key. Tick the option to stop browser shortcuts like Tab or Ctrl+S while you test.

Example

Pressing Enter shows key "Enter", code "Enter" and keyCode 13. The numpad Enter has the same key but code "NumpadEnter" and location 3.

Pressing Shift + A shows key "A" (capital), code "KeyA" and keyCode 65, with Shift in the modifiers.

Frequently asked questions

Should I use event.key, event.code or keyCode?

Use event.key when you care about the character typed (it follows the user’s keyboard layout). Use event.code for physical positions, such as WASD in games. keyCode and which are deprecated and kept only for old code.

Why are Ctrl, Shift and Alt shown separately?

They are modifier keys. Each key event tells you whether they were held with ctrlKey, shiftKey, altKey and metaKey (the Windows or Command key).

Why does nothing happen for some keys?

The operating system or browser may capture some combinations before the page sees them, such as Ctrl+W, Alt+Tab or the Windows key.

Popular posts from this blog

Character Counter

Speech to Text Online

Keyboard Tester