KeyboardLayoutMap: get() 方法
get() 方法是 KeyboardLayoutMap 介面的方法,它會返回具有給定鍵的元素。
有效鍵的列表可以在 UI Events KeyboardEvent code Values 規範中找到。
該方法與 Map.prototype.get() 方法其他方面相同。
語法
js
get(key)
引數
key-
要從對映中返回的元素的鍵。
返回值
指定鍵的值。
示例
下面的示例演示瞭如何獲取與英文 QWERTY 鍵盤上的 'W' 鍵對應的鍵盤程式碼的特定於位置或佈局的字串。
js
navigator.keyboard.getLayoutMap().then((keyboardLayoutMap) => {
const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`Press ${upKey} to move up.`);
});
規範
| 規範 |
|---|
| ECMAScript® 2026 語言規範 # sec-map.prototype.get |
瀏覽器相容性
載入中…