-
Notifications
You must be signed in to change notification settings - Fork 11
/
fakedevice.html
85 lines (71 loc) · 2.9 KB
/
fakedevice.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<!doctype html>
<html>
<head>
<title>Use the keyboard as a fake joystick</title>
<script type="text/javascript" src="input.js"></script>
<script type="text/javascript" src="input.fakedevice.js"></script>
<script type="text/javascript">
var gamepad;
function connect() {
gamepad = new Input.Device(new Input.FakeDevice());
var container = document.createElement("div");
container.setAttribute("id", "gamepad");
document.body.appendChild(container);
document.getElementById("start").style.display = "none";
var header = document.createElement("h2");
header.appendChild(document.createTextNode("Gamepad: " + gamepad.id));
container.appendChild(header);
header = document.createElement("h3");
header.appendChild(document.createTextNode("Axes"));
container.appendChild(header);
var ul = document.createElement("ul");
var iter = Object.keys(gamepad.axes);
for (var i in iter) {
var li = document.createElement("li");
var prog = document.createElement("progress");
prog.setAttribute("max", "2");
prog.setAttribute("value", "1");
prog.setAttribute("id", gamepad.id + "-" + iter[i]);
li.appendChild(document.createTextNode(iter[i]));
li.appendChild(prog);
ul.appendChild(li);
}
container.appendChild(ul);
header = document.createElement("h3");
header.appendChild(document.createTextNode("Buttons"));
container.appendChild(header);
ul = document.createElement("ul");
iter = Object.keys(gamepad.buttons);
for (var i in Object.keys(gamepad.buttons)) {
li = document.createElement("li");
prog = document.createElement("progress");
prog.setAttribute("max", "1");
prog.setAttribute("value", "0");
prog.setAttribute("id", gamepad.id + "-" + iter[i]);
li.appendChild(document.createTextNode(iter[i]));
li.appendChild(prog);
ul.appendChild(li);
}
container.appendChild(ul);
window.removeEventListener("keydown", connect, false);
window.mozRequestAnimationFrame(updateStatus);
}
function updateStatus(e) {
var id = gamepad.id + "-";
var iter = Object.keys(gamepad.axes);
for (var i in iter) {
document.getElementById(id + iter[i]).setAttribute("value", gamepad.axes[iter[i]] + 1);
}
iter = Object.keys(gamepad.buttons);
for (var i in iter) {
document.getElementById(id + iter[i]).setAttribute("value", gamepad.buttons[iter[i]]);
}
window.mozRequestAnimationFrame(updateStatus);
}
window.addEventListener("keydown", connect, false);
</script>
</head>
<body>
<h1 id="start">Press a button on your keyboard to start</h1>
</body>
</html>