🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › UI_Events › Keyboard_event_code_values
Code values for keyboard events - Web APIs | MDN
This table shows the Windows scan codes representing keys and the KeyboardEvent.code values which correspond to those hardware keys. Only keys which generate scan codes on Windows are listed.
🌐
freeCodeCamp
freecodecamp.org › news › javascript-keycode-list-keypress-event-key-codes
JavaScript Keycode List – Keypress Event Key Codes for Enter, Space, Backspace, and More
January 8, 2021 - The keyboard event types we may not ever need. Which properties you need in practice and how different browsers handle them. What is deprecated, and what's in use. A playground to try things out as we learn. Finally, the current list of key codes for reference and future use.
🌐
W3C
w3.org › TR › uievents-code
UI Events KeyboardEvent code Values
April 22, 2025 - For these and other alternative modal keyboards, the key values "Alphanumeric", "CapsLock", "NumLock", and "SymbolLock" are RECOMMENDED for the keys which switch between different modes. This section defines a list of values which are appropriate for use as code values.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › KeyboardEvent › code
KeyboardEvent: code property - Web APIs | MDN
To determine what character corresponds with the key event, use the KeyboardEvent.key property instead. The code values for Windows, Linux, and macOS are listed on the KeyboardEvent: code values page.
🌐
Toptal
toptal.com › developers › keycode › table
JavaScript Key Code List & Table | Toptal®
Easily find every JavaScript Key Code in one table. Get started now.
🌐
Toptal
toptal.com › developers › keycode
JavaScript Key Code Event Tool | Toptal®
KeyCode.Info allows users to press any key and instantly get the JavaScript Key or Key Code KeyboardEvent. Check out the Tool and Event List.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › KeyboardEvent › keyCode
KeyboardEvent: keyCode property - Web APIs | MDN
For example, if the active keyboard layout is Russian, the keyCode value of both the "Period" key and "Slash" key are 190 (KeyEvent.DOM_VK_PERIOD). If you need to distinguish those keys but you don't want to support all keyboard layouts in the world by yourself, you should probably use KeyboardEvent.code.
🌐
W3Schools
w3schools.com › jsref › event_key_code.asp
KeyboardEvent code Property
Animation Events Clipboard Events Drag Events Events Focus Events HashChange Events Input Events Keyboard Events Mouse Events PageTransition Events PopState Events Progress Events Storage Events Touch Events Transition Events Ui Events Wheel Events HTML Event Properties · altKey (Mouse) altKey (Key) animationName bubbles button buttons cancelable charCode clientX clientY code ctrlKey (Mouse) ctrlKey (Key) currentTarget data defaultPrevented deltaX deltaY deltaZ deltaMode detail elapsedTime elapsedTime eventPhase inputType isTrusted key keyCode location metaKey (Mouse) metaKey (Key) newURL oldURL offsetX offsetY pageX pageY persisted propertyName relatedTarget relatedTarget screenX screenY shiftKey (Mouse) shiftKey (Key) target targetTouches timeStamp touches type which (Mouse) which (Key) view HTML Event Methods
🌐
CodePen
codepen.io › denilsonsa › pen › epmoma
KeyboardEvent.key and KeyBoardEvent.code
If you are building a game that uses <a href="https://en.wikipedia.org/wiki/Arrow_keys#WASD_keys">WASD keys</a>, then use <code>.code</code>, as it will work across any keyboard layout. However, if you are interested in detecting if specific inputs were pressed (e.g. arrows, home, end, page up, page down), then use <code>.key</code>. I believe most applications will end up using <code>.key</code> instead of <code>.code</code>.</p> <h2>Demo: type in the textarea</h2> <table id="form"> <thead> <tr> <th colspan="3">Show events of these types:</th> <th rowspan="2">Miscellaneous options</th> </tr>
Find elsewhere
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › API › UI_Events › Keyboard_event_key_values
Key values for keyboard events - Web APIs | MDN
January 7, 2026 - The tables below list the standard values for the KeyboardEvent.key property, with an explanation of what the key is typically used for. Corresponding virtual keycodes for common platforms are included where available.
🌐
CodeShack
codeshack.io › home › tools › keyboard event code tester
Keyboard Event Code Tester - Find JavaScript Key Codes
Every key press on a webpage fires JavaScript events like `keydown`, `keyup`, and `keypress`. This tool captures those events and displays all the important information, like `event.key` and `event.code`, in real-time. This is useful when you are building keyboard shortcuts or any feature that needs to respond to keyboard input.
🌐
W3C
w3.org › 2002 › 09 › tests › keys.html
Keyboard Events and Codes
Enter some text with uppercase and lowercase letters:
🌐
Keyjs
keyjs.dev
Key.js \ JavaScript keyboard event key codes & key identifiers
👇 Press any key to see JavaScript e.key, e.code, e.which, e.keyCode and more key codes and characters. Better than keycode.info!
🌐
Microsoft Learn
learn.microsoft.com › en-us › windows › win32 › inputdev › virtual-key-codes
Virtual-Key Codes (Winuser.h) - Win32 apps | Microsoft Learn
The following table shows the symbolic constant names, hexadecimal values, and mouse or keyboard equivalents for the virtual-key codes used by the system. The codes are listed in numeric order.
🌐
W3Schools
w3schools.com › jsref › event_key_keycode.asp
KeyboardEvent keyCode Property
Animation Events Clipboard Events Drag Events Events Focus Events HashChange Events Input Events Keyboard Events Mouse Events PageTransition Events PopState Events Progress Events Storage Events Touch Events Transition Events Ui Events Wheel Events HTML Event Properties · altKey (Mouse) altKey (Key) animationName bubbles button buttons cancelable charCode clientX clientY code ctrlKey (Mouse) ctrlKey (Key) currentTarget data defaultPrevented deltaX deltaY deltaZ deltaMode detail elapsedTime elapsedTime eventPhase inputType isTrusted key keyCode location metaKey (Mouse) metaKey (Key) newURL oldURL offsetX offsetY pageX pageY persisted propertyName relatedTarget relatedTarget screenX screenY shiftKey (Mouse) shiftKey (Key) target targetTouches timeStamp touches type which (Mouse) which (Key) view HTML Event Methods
🌐
GCCTech
gcctech.org › csc › javascript › javascript_keycodes.htm
JavaScript Keycodes - GC Computer Technology
The keydown event occurs when the keyboard key is pressed, and it is followed at once by the execution of keypress event.
🌐
ForeUI
foreui.com › articles › Key_Code_Table.htm
Key Code Table
Provide the list of key code that can be used in condition express.
Top answer
1 of 4
6

It is impossible to reliably guess the key from the code, because the code refers to the physical key being pressed, while the value of key depends on the keyboard layout. For example on my german QWERTZ keyboard the key corresponding to the code 'BracketLeft' is 'ü' while on an american QWERTY keyboard it would be ']'.

If your goal is to tell your users which key to press to trigger some action you could try some other ways:

  • Create an image of a keyboard on which the key is highlighted and display that as a hint
  • Somehow get your users to press the key so you can observe the actual event and learn the appropiate key value that way
  • Create code -> key mappings for the keyboard layouts your users are most likely to use and guess the correct mapping depending on browser locale and/or observed keyboard events

None of these options are perfect but I think can get you pretty close.

2 of 4
2

I was trying to do the same thing as you, showing in the UI the current key values for the user that correspond to the KeyboardEvent.code (the physical key).

Short answer:

Not possible at the moment. It's probably better to use one of the suggestions made by @seabeast.

Long answer:

As today, there is a non-standardized way of getting this in Chrome based browsers: KeyBoardLayoutMap. Example from MDN:

Copywindow.addEventListener("keydown", function (e) {   
   const keyboard = navigator.keyboard;   
   keyboard.getLayoutMap().then((keyboardLayoutMap) => {
      const keyValue = keyboardLayoutMap.get(e.code);
      console.log(`code: ${e.code}  <->  key: ${e.key}  <->  result: ${keyValue}`);  
   }); 
});

This code would not be reliable for anything serious as keyboardLayoutMap.get() returns undefined for keys outside of the printable chars in the alphanumeric section. I've even found that in Chrome v93 is giving me swapped values for key < and º in a European Spanish layout.

My other failed attempt was to dispatch fake keyboard events before the user can do anything. The problem is you have to manually populate each property in the event object (i.e.: you have to know the code and key beforehand).

The specification says absolutely nothing about how the two might relate to each other in a consistent way.

Honestly not sure how a professional web app might be managing this kind of stuff, maybe as @seabeast said: an educated guess that connects the locale in window.navigator.language to a saved code->key map of its most common kb layout?

Conclusion:

If nothing of the previous suggestions satisfies you, you could always try to minimize confusion to the end-user. I'll probably:

  1. Stick to the event.key property.
  2. Give user the possibility to rebind the keys to his/her needs.
  3. And try not to get too much creative with your default shortcut set. Just using the common ASCII/English characters in the alphanumeric section and maybe some of the function section if needed.

The reason is that the user can usually link those key values representations in your UI to a physical key on his/her keyboard, and when that fails he/she can rebind the key.

🌐
Chrome Developers
developer.chrome.com › blog › what’s new with keyboardevents? keys and codes!
What’s new with KeyboardEvents? Keys and codes! | Blog | Chrome for Developers
April 18, 2016 - To give a concrete example, let’s assume your user is using a U.S. keyboard with a QWERTY keyboard layout. Pressing the physical Q key on that keyboard will result in a KeyboardEvent with a code attribute set to "KeyQ". This is true regardless of keyboard layout, and regardless of any other modifier keys.
🌐
Can I Use
caniuse.com › keyboardevent-code
KeyboardEvent.code | Can I use... Support tables for HTML5, CSS3, etc
A KeyboardEvent property representing the physical key that was pressed, ignoring the keyboard layout and ignoring whether any modifier keys were active. ... "Some key events, or their values, might be suppressed by the IME in use".