-
Notifications
You must be signed in to change notification settings - Fork 8k
/
index.md
44 lines (31 loc) · 966 Bytes
/
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
---
title: Navigator.getGamepads()
slug: Web/API/Navigator/getGamepads
---
{{ APIRef("Navigator") }}{{SeeCompatTable}}
La méthode **`Navigator.getGamepads()`** renvoie un tableau d'objets {{ domxref("Gamepad") }}, un par contrôleur connecté à la machine.
Des éléments dans le tableau peuvent être `null` si un contrôleur est déconnecté durant la session, ainsi les autres restants gardent le même indice.
## Syntaxe
```js
var arrayGP = navigator.getGamepads();
```
## Exemple
```js
window.addEventListener("gamepadconnected", function (e) {
var gp = navigator.getGamepads()[0];
console.log(
"Contrôleur n°%d connecté : %s. %d boutons, %d axes.",
gp.index,
gp.id,
gp.buttons.length,
gp.axes.length,
);
});
```
## Spécifications
{{Specifications}}
## Compatibilité des navigateurs
{{Compat}}
## Voir aussi
- [Utiliser l'API Gamepad](/fr/docs/Web/Guide/API/Gamepad)
- [L'API Gamepad](/fr/docs/Web/API/Gamepad_API)