-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d343d2
commit b27eec2
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}} |