I was looking through the MDN Web APIs, and I stumbled across navigator.keyboard
. I could see a use for Keyboard.getLayoutMap()
, with setting up controls for games, or fingerprinting, however, I could not think of a use for Keyboard.lock() / .unlock()
. From the MDN Web Docs,
Keyboard.lock() Experimental
The lock() method of the Keyboard interface returns a Promise that resolves after enabling the capture of keypresses for any or all of the keys on the physical keyboard. This method can only capture keys that are granted access by the underlying operating system.
If lock() is called multiple times then only the key codes specified in the most recent call will be locked. Any keys locked by a previous call to lock() are unlocked.
From this, I made the assumption that it would lock key presses from being registered, but upon setting this simple setup, I saw the keys were still being registered.
<input>
<script>navigator.keyboard.lock()</script>
I know that these are still experimental, and are subject to change, but could anyone elaborate on how to use Keyboard.lock()
and what use cases it has.
I searched online, but the only thing I could find for Keyboard.lock()
was the MDN Web Doc itself.