MENU
Keyboard
The Keyboard API allows:
Keyboard mapping: provides an interface for retrieving the string generated by a particular physical key on a keyboard to correctly identify that key to a user.
Keyboard locking: enables a web page to capture keys that are normally reserved by the user agent or the underlying operating system.
The intended use of the Keyboard API is by web applications such as games or remote access apps that provide a full-screen immersive experience.
Keyboard Mapping...(click FULL to see the demo)
RESETRUNFULL
RESETRUNFULL
<!DOCTYPE html><html><body><script>
navigator.keyboard.getLayoutMap()
.then(keyboardLayoutMap => {
document.write(keyboardLayoutMap.get('KeyW')); // w
document.write(keyboardLayoutMap.get('Comma')); // ,
});
</script></body></html>
The following example captures keys, regardless of which modifiers are used with the key press, even if the combination is reserved by the user agent.
navigator.keyboard.lock(); // capture all keys
navigator.keyboard.lock( ["KeyW","KeyA","KeyS","KeyD"])
;navigator.keyboard.unlock();