KeyboardLayoutMap
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
TheKeyboardLayoutMap interface of theKeyboard API is a read-only object with functions for retrieving the string associated with specific physical keys.
AKeyboardLayoutMap instance is a read-onlyMap-like object, in which each key is a string identifying the unique physical key on the keyboard (a "key code"), and the corresponding value is the associated key attribute value (which may be affected by the keyboard layout, and so on).
A list of valid keys is found in theUI Events KeyboardEvent code Values specification.
In this article
Instance properties
KeyboardLayoutMap.sizeRead onlyExperimentalReturns the number of elements in the
KeyboardLayoutMapobject.
Instance methods
KeyboardLayoutMap[Symbol.iterator]()ExperimentalReturns a newIterator object that contains the key/value pairs.
KeyboardLayoutMap.entries()ExperimentalReturns a newIterator object that contains the key/value pairs.
KeyboardLayoutMap.forEach()ExperimentalExecutes a provided function once for each element of
KeyboardLayoutMap.KeyboardLayoutMap.get()ExperimentalReturns the element with the given key from the
KeyboardLayoutMapobject.KeyboardLayoutMap.has()ExperimentalReturns a boolean indicating whether the
KeyboardLayoutMapobject has an element with the specified key.KeyboardLayoutMap.keys()ExperimentalReturns a newIterator object that contains the keys for each index in the
KeyboardLayoutMapobject.KeyboardLayoutMap.values()ExperimentalReturns a newIterator object that contains the values for each index in the
KeyboardLayoutMapobject.
Examples
The following example demonstrates how to get the location- or layout-specific string associated with the keyboard code that corresponds to the 'W' key on an English QWERTY keyboard.
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => { const upKey = keyboardLayoutMap.get("KeyW"); window.alert(`Press ${upKey} to move up.`);});Specifications
| Specification |
|---|
| Keyboard Map> # keyboardlayoutmap-interface> |