Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
skyclouds2001 authored Oct 2, 2024
1 parent 2d343d2 commit b27eec2
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions files/zh-cn/web/api/keyboard/getlayoutmap/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
title: Keyboard:getLayoutMap() 方法
slug: Web/API/Keyboard/getLayoutMap
l10n:
sourceCommit: 165d921f6f96711117be2b6513944ce36c70703f
---

{{APIRef("Keyboard API")}}{{SeeCompatTable}}{{securecontext_header}}

{{domxref("Keyboard")}} 接口的 **`getLayoutMap()`** 方法返回一个 {{jsxref('Promise')}},该实例兑现一个 {{domxref('KeyboardLayoutMap')}} 实例,该实例是一个类 map 的对象,具有检索与特定物理键关联的字符串的功能。

## 语法

```js-nolint
getLayoutMap()
```

### 参数

无。

### 返回值

一个 {{jsxref('Promise')}},兑现一个 {{domxref('KeyboardLayoutMap')}} 实例。

### 异常

- `SecurityError` {{domxref("DOMException")}}
- : 如果调用被[权限策略](/zh-CN/docs/Web/HTTP/Permissions_Policy)阻止,则抛出此异常。

## 示例

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

```js
const keyboard = navigator.keyboard;
keyboard.getLayoutMap().then((keyboardLayoutMap) => {
const upKey = keyboardLayoutMap.get("KeyW");
window.alert(`Press ${upKey} to move up.`);
});
```

## 规范

{{Specifications}}

## 浏览器兼容性

{{Compat}}

## 参见

- {{jsxref("Intl")}}

0 comments on commit b27eec2

Please sign in to comment.