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
|
---
title: GamepadEvent
slug: Web/API/GamepadEvent
translation_of: Web/API/GamepadEvent
---
<pre class="syntaxbox notranslate">{{APIRef("Gamepad API")}}</pre>
<p>The GamepadEvent interface of the Gamepad API contains references to gamepads connected to the system, which is what the gamepad events {{domxref("Window.gamepadconnected")}} and {{domxref("Window.gamepaddisconnected")}} are fired in response to.</p>
<h2 id="Constructor">Constructor</h2>
<dl>
<dt>{{domxref("GamepadEvent.GamepadEvent","GamepadEvent()")}}</dt>
<dd>Returns a new <code>GamepadEvent</code> object.</dd>
</dl>
<h2 id="Properties">Properties</h2>
<dl>
<dt>{{ domxref("GamepadEvent.gamepad") }} {{readonlyInline}}</dt>
<dd>Returns a {{ domxref("Gamepad") }} object, providing access to the associated gamepad data for the event fired.</dd>
</dl>
<h2 id="Examples">Examples</h2>
<p>The gamepad property being called on a fired {{domxref("Window.gamepadconnected")}} event.</p>
<pre class="brush: js notranslate">window.addEventListener("gamepadconnected", function(e) {
console.log("Gamepad connected at index %d: %s. %d buttons, %d axes.",
e.gamepad.index, e.gamepad.id,
e.gamepad.buttons.length, e.gamepad.axes.length);
});</pre>
<p>And on a {{domxref("Window.gamepaddisconnected")}} event.</p>
<pre class="brush: js notranslate">window.addEventListener("gamepaddisconnected", function(e) {
console.log("Gamepad disconnected from index %d: %s",
e.gamepad.index, e.gamepad.id);
});</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("Gamepad", "#gamepadevent-interface", "GamepadEvent")}}</td>
<td>{{Spec2("Gamepad")}}</td>
<td>Initial definition</td>
</tr>
</tbody>
</table>
<h2 id="Browser_compatibility" name="Browser_compatibility">Browser compatibility</h2>
<p>{{Compat("api.GamepadEvent")}}</p>
<h2 id="See_also">See also</h2>
<p><a href="/en-US/docs/Web/Guide/API/Gamepad">Using the Gamepad API</a></p>
|