Keyboard: getLayoutMap() method
Keyboard API
Keyboard API
The getLayoutMap() method of the
Keyboard interface returns a Promise that resolves with
an instance of KeyboardLayoutMap which is a map-like object with
functions for retrieving the strings associated with specific physical keys.
Syntax
getLayoutMap()
Parameters
None.
Return value
A Promise that resolves with an instance of KeyboardLayoutMap.
Exceptions
SecurityErrorDOMException- : Thrown if the call is blocked by a permission policy.
Examples
The following example demonstrates how to get the location- or layout-specific string associated with the key that corresponds to the 'W' key on an English QWERTY keyboard.
const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap) => {
const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`Press ${upKey} to move up.`);
});
Specifications
Browser compatibility
See also
- Intl