JavaScript Key Code Finder: event.key, event.code and keyCode

What is it?

The JavaScript Key Code Finder shows the codes JavaScript gives for any key you press. It shows event.key, event.code, the older keyCode, which side of the keyboard the key is on, and whether Ctrl, Shift or Alt were held.

Who is it for?

Web and game developers adding keyboard shortcuts, testers checking keyboards and layouts, and students learning keyboard events.

How to use it

  1. Press a key (on a phone, tap On a phone? Tap here and type).
  2. Read the values and tap Copy.
  3. Use them in your keydown handler.

Which one to use

Use event.key for the character and event.code for the physical key (it stays the same on QWERTY, AZERTY and other layouts). keyCode is old and deprecated; avoid it in new code.

Example

Pressing Z on a French AZERTY keyboard gives key: "z" but code: "KeyW", because it’s in the W position. Games using WASD should use code.

Errors and how to fix them

  • Nothing shows: click the page first so it has keyboard focus.
  • Some shortcuts don’t register: the browser or system takes them first (Ctrl+W, Alt+Tab, the Windows key).
  • Phones show “Unidentified” or keyCode 229: mobile keyboards often don’t report keys during typing; listen for input events instead.

Questions people ask

  • Does it show modifier keys? Yes, Ctrl, Shift, Alt and Meta states are shown.

Open the tool: JavaScript Key Code Finder

Still stuck?

Contact support. Tell us which tool or page you were using, what you tapped, what you saw, and your phone or computer and browser (for example: Android phone, Chrome). We reply by email.

Questions, or an error not listed here?

Tell us in the comments: what you were doing, the exact message you saw, and your device and browser. We read every comment and add new fixes to this article.