这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
lock()
方法在
键盘
interface returns a
Promise
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.
var promise = Keyboard.lock([keyCodes[]])
keyCodes
可选
数组
of one or more key codes to lock. If no keycodes are provided all keys will be locked. A list of valid code values is found in the
UI Events KeyboardEvent code Values
spec.
A
Promise
.
The following example captures all keypresses.
navigator.keyboard.lock();
The following example captures the "W", "A", "S", and "D" keys. It captures these keys regardless of which modifiers are used with the key press. Assuming a standard US QWERTY layout, registering
"KeyW"
ensures that "W", Shift+"W", Control+"W", Control+Shift+"W", and all other key modifier combinations with "W" are sent to the app. The same applies to for
"KeyA"
,
"KeyS"
and
"KeyD"
.
navigator.keyboard.lock(["KeyW", "KeyA", "KeyS", "KeyD"]);
| 规范 | 状态 | 注释 |
|---|---|---|
|
Keyboard Lock
The definition of 'lock()' in that specification. |
编者草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
lock
|
Chrome 68 | Edge 79 | Firefox No | IE No | Opera 55 | Safari No | WebView Android No | Chrome Android No | Firefox Android No | Opera Android No | Safari iOS No | Samsung Internet Android No |
完整支持
不支持
实验。期望将来行为有所改变。
键盘
getLayoutMap()
lock()
unlock()