-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamepad.html
41 lines (39 loc) · 948 Bytes
/
gamepad.html
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
<!DOCTYPE html>
<html>
<head> </head>
<body>
<h2>Xbox Controller</h2>
<h3>test</h3>
</body>
<script>
var loop
connect = (evt) => {
gamepadAPI.turbo = true;
console.log("Gamepad connected.");
loop = setInterval(()=>{
gamepadAPI.controller = evt.gamepad;
// console.log(gamepadAPI.controller);
}, 100)
};
disconnect = (evt) => {
gamepadAPI.turbo = false;
delete gamepadAPI.controller;
console.log("Gamepad disconnected.");
clearInterval(loop)
};
const gamepadAPI = {
controller: {},
turbo: false,
connect,
disconnect,
update() {},
buttonPressed() {},
buttons: [],
buttonsCache: [],
buttonsStatus: [],
axesStatus: [],
};
window.addEventListener("gamepadconnected", gamepadAPI.connect);
window.addEventListener("gamepaddisconnected", gamepadAPI.disconnect);
</script>
</html>