Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages

Free tool · Developer tools

JavaScript keycode finder

This JavaScript keycode finder reads the key you press and shows every value a keydown handler can see. Pressing Enter gives key "Enter", code "Enter" and keyCode 13, plus lines such as event.key === "Enter" to paste into your code.

  • Free
  • No sign-up
  • Runs in your browser

By Maaz Zindani · Updated

Press any key here
Click here, then press a keyNot listening
Tab is recorded and still moves focus on. Every other key is captured, so the page does not scroll.
A number such as 32 finds the key with that keyCode. A name finds its key and code values.
Example key press

EnterkeyCode 13, code Enter. Press a key in the box to replace this.

  • Example
event.key
"Enter"
event.code
"Enter"
event.keyCode
13
event.which
13
event.location
0 (Standard)
Modifiers held
none
event.repeat
false
Code to paste
  • By key (the character or action)event.key === "Enter"
  • By code (the physical key)event.code === "Enter"
  • Legacy keyCode (deprecated)event.keyCode === 13
  • In a switch statementcase "Enter":

How to use the JavaScript Keycode Finder

  1. Click the dashed box under Press any key here. It says Listening when it has focus.
  2. Press a key, or a shortcut such as Ctrl and S. The values update at once, and held modifiers are listed.
  3. Copy the condition you need from Code to paste. Prefer the key or code line over the keyCode line.
  4. To go the other way, type a number or a key name into Look up a key code or key name.

How do I find the keycode of a key in JavaScript?

A keydown event carries several properties, and the box above shows all of them. For Enter the values are key "Enter", code "Enter", keyCode 13 and which 13, with location 0, which the page names Standard. The conditions that follow from it are event.key === "Enter", event.code === "Enter", event.keyCode === 13.

The Space bar shows why the key value needs care. Its key is a single space character, so the condition is written event.key === " ", and its keyCode is 32. The page names it Space on screen so the value is not invisible. Tab is recorded without being blocked, so you can still move out of the box with the keyboard. Every other key is captured, which is why the arrow keys do not scroll the page while you test them.

The same table works in reverse. Typing 32 into the lookup finds Space, typing 13 finds Enter, and a number with no key behind it gets a plain answer: "No key in the table has the code 999. Press the key in the box above to read its code from your own keyboard."

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

The W3C UI Events specification calls keyCode obsolete and tells authors to use the key attribute in its place, so the page prints that condition last. The two modern properties answer different questions. The key property is the character or action a key produces, so it changes with the layout and the modifiers. The code property names the physical key and ignores both. The W3C code list gives the example of the physical Q key: it reports code "KeyQ" on every layout, and it types q with a US layout but a with a French one.

That is why a shortcut for typed text should use key, and a game that moves with the W, A, S and D keys should use code. Hold Shift and press S and you get key "S" with code "KeyS" while keyCode stays 83. For a Ctrl and S shortcut the page offers event.ctrlKey && event.key === "s", and when Shift is held as well it becomes event.ctrlKey && event.shiftKey && event.key === "S", since the key is now a capital letter.

Modifier keys have a side. Pressing the left Shift key gives key "Shift", code "ShiftLeft", keyCode 16 and location 1, named Left in the list of locations, while the right key gives location 2 and code "ShiftRight". Only code and location tell the two apart, because key and keyCode are the same for both.

JavaScript keycode finder table: keyCode values of common keys

Digits use their ASCII code, so the key 0 is 48 and 9 is 57. Letters use the code of the capital letter, so A is 65 and Z is 90, whether Shift is held or not. The table lists the other keys the lookup knows. The punctuation codes are the values for a US layout, and the W3C UI Events specification lists them as values that can differ by layout, so test them on the keyboards you care about before relying on them.

Keys, their key and code values and the legacy keyCode
Keyevent.keyevent.codekeyCode
BackspaceBackspaceBackspace8
TabTabTab9
EnterEnterEnter13
ShiftShiftShiftLeft16
ControlControlControlLeft17
AltAltAltLeft18
Caps LockCapsLockCapsLock20
EscapeEscapeEscape27
Space" "Space32
Page UpPageUpPageUp33
Page DownPageDownPageDown34
EndEndEnd35
HomeHomeHome36
Arrow LeftArrowLeftArrowLeft37
Arrow UpArrowUpArrowUp38
Arrow RightArrowRightArrowRight39
Arrow DownArrowDownArrowDown40
DeleteDeleteDelete46
F1F1F1112
Semicolon;Semicolon186
Equals sign=Equal187
Comma,Comma188
Minus-Minus189
Period.Period190
Forward slash/Slash191
Backtick`Backquote192
Opening bracket[BracketLeft219
Backslash\Backslash220
Closing bracket]BracketRight221
Single quote'Quote222

Use it with

Questions

How do I get the keycode of a key press in JavaScript?

Add a keydown listener and read event.keyCode, or press the key in the box on this page. Enter gives 13, Escape gives 27 and Space gives 32.

Is event.keyCode deprecated?

Yes. The W3C UI Events specification lists keyCode among obsolete attributes and asks authors to use event.key, and event.code is the choice when the physical key matters.

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

The key property is the character or action produced and depends on layout and modifiers. The code property names the physical key, so it stays the same on every layout.

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

Press the shortcut in the box and copy the last line, for example event.ctrlKey && event.key === "s". Use event.metaKey in place of event.ctrlKey when the shortcut uses the Meta key.

Why does the arrow key not scroll the page here?

The box captures every key except Tab, and stops the default action, so the page stays still while you test. Click outside the box to scroll again.

Does the page send my key presses anywhere?

No. The box listens only while it has focus, and the values are read and shown in your tab without being stored or sent.

The tool's results are computed in your browser by the code on this page, using the sources listed above; the explanations are checked against the tool's own output.