JavaScript Key Codes: event.key, event.code and keyCode

Press a key and instantly see what JavaScript reports for it: event.key, event.code, the old keyCode, which side of the keyboard it is on, and modifiers like Ctrl and Shift, with a ready code snippet.

loading tool

How to find a key code

  1. Click on the page (or tap the box on a phone).
  2. Press any key.
  3. Copy the value or snippet you need.

Questions

Should I use key, code or keyCode?

Use event.key for the character typed and event.code for the physical key (handy for games). keyCode is outdated and should be avoided in new code.

Why do Enter and the number-pad Enter differ?

They share event.key "Enter", but event.code is "Enter" or "NumpadEnter", and location is 0 or 3.

Is my data private?

Yes. Everything happens inside your own browser: nothing you type or choose is uploaded to us or anyone else.

Is it free?

Completely free, with no sign-up, no watermark and no limit on how many times you use it. Light ads keep the site running.