The Keyboard interface of the Keyboard API provides functions that retrieve keyboard layout maps and toggle capturing of key presses from the physical keyboard.
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.
Unlocks all keys captured by the lock() method and returns synchronously.
Example
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.
js
if(navigator.keyboard){const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap)=>{const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`Press ${upKey} to move up.`);});}else{// Do something else.}