KeyboardLayoutMap:get() 方法

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

实验性: 这是一项实验性技术
在将其用于生产之前,请仔细检查浏览器兼容性表格

KeyboardLayoutMap 接口的 get() 方法返回具有给定键盘代码的元素。

UI 事件 KeyboardEvent 代码值规范中可以找到有效键盘代码的列表。

该方法与 Map.prototype.get() 相似。

语法

js
get(key)

参数

key

从映射返回的项目的键盘代码。

返回值

指定键盘代码的值。

示例

下面的示例说明如何获取与英语 QWERTY 键盘上“W”键对应的键盘代码关联的位置或布局特定字符串。

js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
  const upKey = keyboardLayoutMap.get("KeyW");
  window.alert(`${upKey} 向上移动。`);
});

规范

Specification
ECMAScript® 2025 Language Specification
# sec-map.prototype.get

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
get
Experimental

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.

参见