coderef

Keyboard mapLimited availability

The navigator.keyboard.getLayoutMap() API returns a map from key codes to human readable key names. It can be used to describe buttons to the user when using the keyboard as a set of buttons, such as in games.

Not yet supported in all major browsers — check the table and provide a fallback.

Browser support

DesktopChrome
1–68Not supported
69+Supportedsince Sep 4, 2018
Current: 155
Edge
12–18Not supported
79+Supportedsince Jan 15, 2020
Current: 154
Firefox
✕Not supportedup to 157
Current: 157
Safari
✕Not supportedup to 27
Current: 27
MobileChrome Android
18–68Not supported
69+Supportedsince Sep 4, 2018
Current: 155
Firefox Android
✕Not supportedup to 157
Current: 157
Safari iOS
✕Not supportedup to 27
Current: 27

How to use

Not supported in Firefox, Safari, Firefox Android, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.

Example

Full syntax and examples are on MDN: getLayoutMap.

Feature detection

JS · check before using
if ("KeyboardLayoutMap" in globalThis) {
  // KeyboardLayoutMap is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (10). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
Keyboard.getLayoutMap6979✕✕69✕✕
KeyboardLayoutMap6979✕✕69✕✕
KeyboardLayoutMap.@@iterator6979✕✕69✕✕
KeyboardLayoutMap.entries6979✕✕69✕✕
KeyboardLayoutMap.forEach6979✕✕69✕✕
KeyboardLayoutMap.get6979✕✕69✕✕
KeyboardLayoutMap.has6979✕✕69✕✕
KeyboardLayoutMap.keys6979✕✕69✕✕
KeyboardLayoutMap.size6979✕✕69✕✕
KeyboardLayoutMap.values6979✕✕69✕✕