Key codes·Digit1
1
Digit1
keyCode 49

Digit1 key code — keyCode 49

Digits

Digit1 has keyCode 49 and key "1", at location 0.

The number row. Its keyCodes differ from the same digits on the numpad.

code (position)
Digit1
key (US layout)
"1"
With Shift
"!"
keyCode (deprecated)
49
Hexadecimal
0x31
location
0 · Standard
Types a character
Yes
Shares keyCode with
None

In code

Comparing against code keeps working when the layout changes.

window.addEventListener('keydown', e => {
  if (e.code === 'Digit1') {
    // 1
  }
});

code versus key

code is the physical position, the same on a Korean or French keyboard. key is what gets typed and changes — the same spot gives a, A or ㅁ. Use code to ask which spot was pressed, key to ask what was entered.

keyCode has been dropped from the standard. Write new code against code or key; the numbers here are for reading old code.

Keys of the same kind

How to read this

  • code is the position, key is the character typed. Match on code for shortcuts.
  • keyCode is deprecated; use it only to read old code.
  • Left and right Shift share a keyCode and are told apart by location.
  • The 1 on the number row and the 1 on the numpad are different keys — 49 and 97.

Frequently asked questions

Q. What is the keyCode for Digit1?

49, or 0x31 in hexadecimal.

Q. How do I match Digit1 in code?

Compare with e.code === 'Digit1'. Matching on keyCode wobbles between browsers and layouts.

Q. What is this key's location?

0.

Q. Does this key type a character?

Yes — key is "1", and "!" with Shift held.