aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/gamepadbutton/pressed/index.html
blob: 9126b26ddb18445b8bcd8c537fb08e0ea27a1363 (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
---
title: GamepadButton.pressed
slug: Web/API/GamepadButton/pressed
translation_of: Web/API/GamepadButton/pressed
---
<p>{{APIRef("Gamepad API")}}</p>

<p>{{domxref("GamepadButton")}}接口下的 <code><strong>GamepadButton.pressed</strong></code> 属性返回一个表示按钮当然是被按下了 (<code>true</code>) 还是没有被按下 (<code>false</code>) 的布尔值。</p>

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

<pre class="syntaxbox"><span class="idlInterface" id="idl-def-GamepadButton"><span class="idlAttribute">var isPressed = navigator.getGamepads()[0].pressed;
</span></span></pre>

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

<pre class="brush: js">var gp = navigator.getGamepads()[0]; // 获取第一个控制器对象

if(gp.buttons[0].pressed == true) {
  // 响应按钮按下
}</pre>

<h2 id="值"></h2>

<p>一个 {{domxref("boolean")}} (布尔值)。</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("Gamepad", "#widl-GamepadButton-pressed", "GamepadButton.pressed")}}</td>
   <td>{{Spec2("Gamepad")}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

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

<p>{{Compat("api.GamepadButton.pressed")}}</p>

<h2 id="另请参阅">另请参阅</h2>

<ul>
 <li><a href="/en-US/docs/Web/Guide/API/Gamepad">使用 Gamepad API</a></li>
</ul>