Keyboard Event Viewer

Press any key to see its JavaScript event.key, event.code and keyCode, and copy a ready-made keyboard shortcut check.

Runs in your browser. Nothing is uploaded.

Press any key

Click here first, then type

event.key
–
event.code
–
event.keyCode (old)
–
event.location
–
Modifier keys
–
event.repeat
–

Check for this key in JavaScript

// Press a key or shortcut

Recent keys

EventkeycodekeyCodeShortcut

Keys you press appear here.

How to use the Keyboard Event Viewer

  1. Click the large box (or Tab to it) so it has focus.
  2. Press any key or shortcut, for example Ctrl + Shift + K.
  3. Read event.key, event.code, the old keyCode, the key’s location and which modifier keys were held.
  4. Copy the ready-made JavaScript condition for that key or shortcut.
  5. Look at the list of recent keydown and keyup events to see the exact order.

See exactly what the browser reports

Keyboard shortcuts, games, editors and accessible widgets all react to key presses, and the browser reports each one through a keyboard event with several properties that are easy to confuse. Which value should a shortcut check? What does the right Shift key report? What happens on a French keyboard? This viewer shows every property the moment you press a key.

The properties

  • event.key: the value of the key, such as "a", "A", "?", "Enter" or "ArrowLeft". It depends on the keyboard layout and modifier keys.
  • event.code: the physical key, such as KeyA, Digit1, ShiftRight or Numpad5. It doesn’t change with the layout.
  • event.keyCode: the old numeric code, deprecated but still found in older code.
  • event.location: whether the key is the standard one, the left or right copy (Shift, Ctrl, Alt), or on the number pad.
  • Modifier keys: Ctrl, Alt (Option on a Mac), Shift and Meta (Windows key or Cmd).
  • event.repeat: true while a key is held down and repeating.

Copy-ready JavaScript

For every key or shortcut, the viewer writes an if condition for a keydown handler. For shortcuts with Ctrl, Alt or Cmd and a letter or digit, it checks event.code, so the shortcut sits on the same key on every keyboard layout. For other keys it checks event.key. If you press a shortcut the browser keeps for itself, such as Ctrl + W, you get a warning, because pages can’t reliably use it.

Test a keyboard

The viewer is also a quick keyboard tester: press each key and check that it registers. The recent events list shows keydown and keyup in order, which helps spot stuck or doubled keys.

Everything runs in your browser and nothing is recorded. To build and test a page that uses the shortcut, try the HTML, CSS & JS Playground.

Frequently asked questions

What is the difference between event.key and event.code?

event.key is the character or name the key produces, so it changes with the keyboard layout and Shift: “a”, “A”, “é” or “Enter”. event.code is the physical key position, such as KeyA, and stays the same on every layout. Use key for text and code for shortcuts based on position.

Should I still use keyCode?

No. keyCode and which are deprecated and inconsistent between layouts and browsers. They are shown for reading old code, but new code should use key or code.

Why can’t my page use Ctrl + W or Ctrl + T?

Browsers keep some shortcuts, such as closing and opening tabs, for themselves and don’t let pages override them. The tool warns you when you press one.

Why is Tab not captured?

So you can always move focus away from the box with the keyboard. Other keys are captured while the box has focus and the stop option is ticked.

Is anything recorded or sent?

No. Key presses are only shown on this page and are not stored or sent anywhere.

Tutorials

Tutorial · 7 min · intermediate

How to add a keyboard shortcut to a web app

Find the right key values with the Keyboard Event Viewer, write a layout-safe shortcut handler, and avoid clashing with browser and typing shortcuts.