aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/keyboardevent/metakey/index.html
blob: 8548733aed97a92d0d5443c479681ca9f58f9bf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
---
title: KeyboardEvent.metaKey
slug: Web/API/KeyboardEvent/metaKey
tags:
  - API
  - MouseEvent
translation_of: Web/API/KeyboardEvent/metaKey
---
<p>{{APIRef("DOM Events")}}</p>

<p><strong><code>KeyboardEvent.metaKey</code></strong> 为只读属性,返回一个 {{jsxref("Boolean", "布尔值")}},在事件发生时,用于指示 <kbd>Meta</kbd> 键是按下状态(<code style="font-style: normal;">true</code>),还是释放状态(<code style="font-style: normal;">false</code>)。</p>

<div class="note">
<p>备注:在MAC键盘上,表示 Command 键(<kbd></kbd>),在Windows键盘上,表示 Windows 键(<kbd></kbd>)。</p>
</div>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">var metaKeyPressed = <em>instanceOfKeyboardEvent</em>.metaKey
</pre>

<h3 id="返回值">返回值</h3>

<p>一个布尔值</p>

<h2 id="Example" name="Example">示例</h2>

<pre class="brush: js"> function goInput(e) {
 // 检测metaKey值
   if (e.metaKey) {
        // 继续处理事件
     superSizeOutput(e);
   } else {
     doOutput(e);
   }
 }
</pre>

<p>{{ EmbedLiveSample('Example', 400, 36) }}</p>

<h2 id="规范">规范</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">规范版本</th>
   <th scope="col">规范状态</th>
   <th scope="col">备注</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Events','#widl-KeyboardEvent-ctrlKey','KeyboardEvent.ctrlKey')}}</td>
   <td>{{Spec2('DOM3 Events')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>

<p>{{Compat("api.KeyboardEvent.metaKey")}}</p>

<h2 id="See_also" name="See_also">相关链接</h2>

<ul>
 <li>{{ domxref("KeyboardEvent") }}</li>
</ul>