-
Notifications
You must be signed in to change notification settings - Fork 4
/
PointerLockLog.html
138 lines (131 loc) · 4.63 KB
/
PointerLockLog.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!doctype html>
<html>
<body>
<p><a href="#" id="reqPointerLock">Request pointer lock</a></p>
<p>
<label><input id="outputPausedCheckbox" type="checkbox" disabled> Output Paused.</label>
Press any key to <span id="pauseOutput">pause</span> output, and reset movementXSum/movementYSum.
</p>
<p><label><input id="disableScrollCheckbox" type="checkbox"> Disable Scrolling</label></p>
<table>
<tr>
<td>
<pre>time in seconds,</pre>
</td>
<td align="right">
<pre>event#,</pre>
</td>
<td align="right">
<pre>screenX,</pre>
</td>
<td align="right">
<pre>movementX,</pre>
</td>
<td align="right">
<pre>movementXSum,</pre>
</td>
<td align="right">
<pre>screenY,</pre>
</td>
<td align="right">
<pre>movementY,</pre>
</td>
<td align="right">
<pre>movementYSum,</pre>
</td>
<td align="right">
<pre>stateChange</pre>
</td>
</tr>
<tr>
<td>
<pre id="timeOutput"></pre>
</td>
<td align="right">
<pre id="counterOutput"></pre>
</td>
<td align="right">
<pre id="screenXOutput"></pre>
</td>
<td align="right">
<pre id="movementXOutput"></pre>
</td>
<td align="right">
<pre id="movementXSumOutput"></pre>
</td>
<td align="right">
<pre id="screenYOutput"></pre>
</td>
<td align="right">
<pre id="movementYOutput"></pre>
</td>
<td align="right">
<pre id="movementYSumOutput"></pre>
</td>
<td align="right">
<pre id="stateOutput"></pre>
</td>
</tr>
</table>
<script>
"use strict";
let maxLogSize = 200;
let outputEnabled = true;
let eventCounter = 0;
let movementXSum = 0;
let movementYSum = 0;
// Init the size of page so that scroll bars do not adjust.
let preElements = document.getElementsByTagName("pre");
for (let i = 0; i < preElements.length; i++) {
if (!preElements[i].innerText)
preElements[i].innerText = ".\n".repeat(maxLogSize);
}
function pushStringToTopOfPreElement(value, element) {
if (!outputEnabled)
return;
let a = element.innerText.split("\n");
a.unshift(value);
a = a.slice(0, maxLogSize);
element.innerText = a.join("\n");
}
document.addEventListener('keydown', function() {
movementYSum = 0;
outputEnabled = !outputEnabled;
pauseOutput.innerText = outputEnabled ? "pause" : "unpause";
outputPausedCheckbox.checked = !outputEnabled;
});
document.addEventListener('mousemove', function(e) {
eventCounter++;
movementXSum += e.movementX;
movementYSum += e.movementY;
pushStringToTopOfPreElement(Date.now()/1000, timeOutput);
pushStringToTopOfPreElement(eventCounter, counterOutput);
pushStringToTopOfPreElement(e.screenX, screenXOutput);
pushStringToTopOfPreElement(e.movementX, movementXOutput);
pushStringToTopOfPreElement(movementXSum, movementXSumOutput);
pushStringToTopOfPreElement(e.screenY, screenYOutput);
pushStringToTopOfPreElement(e.movementY, movementYOutput);
pushStringToTopOfPreElement(movementYSum, movementYSumOutput);
pushStringToTopOfPreElement(document.pointerLockElement ? "locked" : "unlocked", stateOutput);
});
document.addEventListener('pointerlockchange', function(e) {
eventCounter++;
pushStringToTopOfPreElement(Date.now()/1000, timeOutput);
pushStringToTopOfPreElement(eventCounter, counterOutput);
pushStringToTopOfPreElement(".", screenXOutput);
pushStringToTopOfPreElement(".", movementXOutput);
pushStringToTopOfPreElement(movementXSum, movementXSumOutput);
pushStringToTopOfPreElement(".", screenYOutput);
pushStringToTopOfPreElement(".", movementYOutput);
pushStringToTopOfPreElement(movementYSum, movementYSumOutput);
pushStringToTopOfPreElement("change: " + (document.pointerLockElement ? "locked" : "unlocked"), stateOutput);
});
document.getElementById('reqPointerLock').addEventListener('click', function() {
document.body.requestPointerLock();
});
disableScrollCheckbox.onchange = () => {
document.body.style.overflow = disableScrollCheckbox.checked ? "hidden" : "";
}
</script>
</body>
</html>