From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/api/keyboard/index.html | 68 +++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 files/zh-cn/web/api/keyboard/index.html (limited to 'files/zh-cn/web/api/keyboard') diff --git a/files/zh-cn/web/api/keyboard/index.html b/files/zh-cn/web/api/keyboard/index.html new file mode 100644 index 0000000000..eb6ab10aa2 --- /dev/null +++ b/files/zh-cn/web/api/keyboard/index.html @@ -0,0 +1,68 @@ +--- +title: Keyboard +slug: Web/API/Keyboard +translation_of: Web/API/Keyboard +--- +
{{SeeCompatTable}}{{APIRef("Keyboard API")}}
+ +

The Keyboard interface of the the Keyboard API provides functions that retrieve keyboard layout maps and toggle capturing of key presses from the physical keyboard.

+ +

A list of valid code values is found in the UI Events KeyboardEvent code Values spec.

+ +

Properties

+ +

None.

+ +

Methods

+ +
+
{{domxref('Keyboard.getLayoutMap()')}} {{experimental_inline}}
+
Returns a {{jsxref('Promise')}} that resolves with an instance of {{domxref('KeyboardLayoutMap')}} which is a map-like object with functions for retrieving the strings associated with specific physical keys.
+
{{domxref('Keyboard.lock()')}} {{experimental_inline}}
+
Returns a {{jsxref('Promise')}} after enabling the capture of keypresses for any or all of the keys on the physical keyboard.
+
{{domxref('Keyboard.unlock()')}} {{experimental_inline}}
+
Unlocks all keys captured by the lock() method and returns synchronously.
+
+ +

Example

+ +

The following example demonstrates how to get the location- or layout-specific string associated with the key that corresponds to the 'W' key on an English QWERTY keyboard.

+ +
if (navigator.keyboard) {
+  var keyboard = navigator.keyboard;
+  keyboard.getLayoutMap()
+  .then(keyboardLayoutMap => {
+    var upKey = keyboardLayoutMap.get('KeyW');
+    window.alert('Press ' + upKey + ' to move up.');
+  });
+} else {
+  // Do something else.
+}
+ +

Specifications

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('Keyboard Map','#keyboard-interface','Keyboard')}}{{Spec2('Keyboard Map')}}Initial definition.
{{SpecName('Keyboard Lock','#keyboard-interface','Keyboard')}}{{Spec2('Keyboard Lock')}}Adds lock() and unlock().
+ +

Browser compatibility

+ + + +

{{Compat("api.Keyboard")}}

-- cgit v1.2.3-54-g00ecf