aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/keyboard
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/keyboard')
-rw-r--r--files/zh-cn/web/api/keyboard/index.html68
1 files changed, 68 insertions, 0 deletions
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
+---
+<div>{{SeeCompatTable}}{{APIRef("Keyboard API")}}</div>
+
+<p><span class="seoSummary">The <strong><code>Keyboard</code></strong> interface of the the <a href="/docs/Web/API/Keyboard_API">Keyboard API</a> provides functions that retrieve keyboard layout maps and toggle capturing of key presses from the physical keyboard.</span></p>
+
+<p>A list of valid code values is found in the <a href="https://www.w3.org/TR/uievents-code/#key-alphanumeric-writing-system">UI Events KeyboardEvent code Values</a> spec.</p>
+
+<h2 id="Properties">Properties</h2>
+
+<p>None.</p>
+
+<h2 id="Methods">Methods</h2>
+
+<dl>
+ <dt>{{domxref('Keyboard.getLayoutMap()')}} {{experimental_inline}}</dt>
+ <dd>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.</dd>
+ <dt>{{domxref('Keyboard.lock()')}} {{experimental_inline}}</dt>
+ <dd>Returns a {{jsxref('Promise')}} after enabling the capture of keypresses for any or all of the keys on the physical keyboard.</dd>
+ <dt>{{domxref('Keyboard.unlock()')}} {{experimental_inline}}</dt>
+ <dd>Unlocks all keys captured by the <code>lock()</code> method and returns synchronously.</dd>
+</dl>
+
+<h2 id="Example">Example</h2>
+
+<p>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.</p>
+
+<pre class="brush: js">if (navigator.keyboard) {
+ var keyboard = navigator.keyboard;
+ keyboard.getLayoutMap()
+ .then(keyboardLayoutMap =&gt; {
+ var upKey = keyboardLayoutMap.get('KeyW');
+ window.alert('Press ' + upKey + ' to move up.');
+ });
+} else {
+ // Do something else.
+}</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Keyboard Map','#keyboard-interface','Keyboard')}}</td>
+ <td>{{Spec2('Keyboard Map')}}</td>
+ <td>Initial definition.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('Keyboard Lock','#keyboard-interface','Keyboard')}}</td>
+ <td>{{Spec2('Keyboard Lock')}}</td>
+ <td>Adds <code>lock()</code> and <code>unlock()</code>.</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+
+
+<p>{{Compat("api.Keyboard")}}</p>