Keyboard:getLayoutMap() 方法
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Keyboard
接口的 getLayoutMap()
方法返回一个 Promise
,其会兑现一个 KeyboardLayoutMap
实例,该实例是一个类 map 的对象,具有检索与特定物理键关联的字符串的功能。
语法
js
getLayoutMap()
参数
无。
返回值
一个 Promise
,其会兑现一个 KeyboardLayoutMap
实例。
异常
SecurityError
DOMException
-
如果调用被权限策略阻止,则抛出此异常。
示例
下面的示例演示如何获取与英语 QWERTY 键盘上“W”键对应的键关联的位置或布局的特定字符串。
js
const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap) => {
const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`按下 ${upKey} 以向上移动。`);
});
规范
Specification |
---|
Keyboard Map # h-keyboard-getlayoutmap |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
getLayoutMap |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.