elefcode

JavaScript Keycode & Key Event Tester

Press any key to see its event.key, event.code, keyCode and modifiers.

Press any key…On a phone or tablet, use a hardware keyboard — on-screen keyboards report most keys as “Unidentified”.

Advertisement

Guide

About the JavaScript Keycode & Key Event Tester

When a key is pressed, the browser fires a keydown event with several properties describing it. Which one to check depends on what you need — the character typed, the physical key, or compatibility with old code. This tester shows them all for any key you press, so you can write a keyboard shortcut or debug one without guessing.

event.key vs event.code vs keyCode

  • event.key is the value of the key — "a", "A", "Enter". It follows the keyboard layout and Shift, and is the one to use for most shortcuts.
  • event.code is the physical key position, such as "KeyA", whatever the layout. Use it for games and WASD-style controls.
  • event.keyCode and event.which are numeric codes that are deprecated and inconsistent across layouts, but still appear in older code.

Common key values

Enter is "Enter" (keyCode 13), Escape is "Escape" (27), Space is " " (32), Tab is "Tab" (9), and the arrows are "ArrowLeft", "ArrowUp", "ArrowRight" and "ArrowDown" (37–40). Press any key above to check others.

How to use it

  1. 1Click on the page so it has keyboard focus.
  2. 2Press a key or key combination.
  3. 3Read its properties, or click one to copy it.
  4. 4Copy the generated handler to use that key in your code.

Frequently asked questions

What is the keyCode for Enter?

event.keyCode is 13 for Enter. In modern code check event.key === "Enter" instead.

Is keyCode deprecated?

Yes. keyCode and which are deprecated in favour of key and code. Browsers still support them for old code, but new code should not rely on them.

How do I detect Ctrl+S or Cmd+S?

Listen for keydown and check (event.ctrlKey || event.metaKey) && event.key === "s", then call event.preventDefault() to stop the browser’s save dialog.

Why does my phone show “Unidentified”?

On-screen keyboards on Android often send keydown with key "Unidentified" and keyCode 229 while composing text. Listen for input events instead when handling touch keyboards.

What is event.location?

It tells left and right modifier keys apart and flags the numeric keypad: 0 standard, 1 left, 2 right, 3 numpad.

Related tools