--- title: Keyboard slug: Web/API/Keyboard translation_of: Web/API/Keyboard ---
The Keyboard interface of the the Keyboard API provides functions that retrieve keyboard layout maps and toggle capturing of key presses from the physical keyboard.
A list of valid code values is found in the UI Events KeyboardEvent code Values spec.
None.
lock() method and returns synchronously.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.
if (navigator.keyboard) {
var keyboard = navigator.keyboard;
keyboard.getLayoutMap()
.then(keyboardLayoutMap => {
var upKey = keyboardLayoutMap.get('KeyW');
window.alert('Press ' + upKey + ' to move up.');
});
} else {
// Do something else.
}
| Specification | Status | Comment |
|---|---|---|
| {{SpecName('Keyboard Map','#keyboard-interface','Keyboard')}} | {{Spec2('Keyboard Map')}} | Initial definition. |
| {{SpecName('Keyboard Lock','#keyboard-interface','Keyboard')}} | {{Spec2('Keyboard Lock')}} | Adds lock() and unlock(). |
{{Compat("api.Keyboard")}}