-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
47 lines (34 loc) · 1.14 KB
/
index.md
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
---
title: "GamepadEvent: gamepad property"
short-title: gamepad
slug: Web/API/GamepadEvent/gamepad
page-type: web-api-instance-property
browser-compat: api.GamepadEvent.gamepad
---
{{APIRef("Gamepad API")}}{{SecureContext_Header}}
The **`GamepadEvent.gamepad`** property of the
**{{domxref("GamepadEvent")}} interface** returns a {{domxref("Gamepad")}}
object, providing access to the associated gamepad data for fired
{{domxref("Window.gamepadconnected_event", "gamepadconnected")}} and {{domxref("Window.gamepaddisconnected_event", "gamepaddisconnected")}} events.
## Value
A {{domxref("Gamepad")}} object.
## Examples
The `gamepad` property being called on a fired
{{domxref("Window.gamepadconnected_event", "gamepadconnected")}} event.
```js
window.addEventListener("gamepadconnected", (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,
);
});
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
[Using the Gamepad API](/en-US/docs/Web/API/Gamepad_API/Using_the_Gamepad_API)