forked from creationix/node-gamepad
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsample.js
More file actions
43 lines (36 loc) · 938 Bytes
/
sample.js
File metadata and controls
43 lines (36 loc) · 938 Bytes
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
var gamepad = require("./.");
// 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,
});
});
gamepad.on("attach", function (id, state) {
console.log("attach", state);
});