-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgamepad.js
39 lines (33 loc) · 861 Bytes
/
gamepad.js
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
var gamepad = require("gamepad");
// Initialize the library
gamepad.init()
// List the state of all currently attached devices
for (var i = 0, l = gamepad.numDevices(); i < l; i++) {
console.log(i, gamepad.deviceAtIndex());
}
// Create a game loop and poll for events
setInterval(gamepad.processEvents, 16);
// Scan for new gamepads as a slower rate
setInterval(gamepad.detectDevices, 500);
// Listen for move events on all gamepads
gamepad.on("move", function (id, axis, value) {
console.log("move", {
id: id,
axis: axis,
value: value,
});
});
// Listen for button up events on all gamepads
gamepad.on("up", function (id, num) {
console.log("up", {
id: id,
num: num,
});
});
// Listen for button down events on all gamepads
gamepad.on("down", function (id, num) {
console.log("down", {
id: id,
num: num,
});
});