-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResponse.html
More file actions
134 lines (131 loc) · 4.14 KB
/
Copy pathResponse.html
File metadata and controls
134 lines (131 loc) · 4.14 KB
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
<!doctype html>
<head>
<style>
.DrawCanvas {
width: 9999px;
height: 9999px;
}
</style>
</head>
<body oncontextmenu="return false">
<canvas id="DrawCanvas"></canvas>
<h1>Controls</h1>
<label for="res">LongSide Resolution</label>
<input type="number" id="res" name="res"
min="50" value="1920">
<button type="button" onclick="ButtonFunction()">Start/Stop</button> <button type="button" onclick="ctx.canvas.width = window.innerWidth; ctx.canvas.height = window.innerHeight;">resize</button>
<script>
var ctx = document.getElementById("DrawCanvas").getContext("2d");
ctx.canvas.width = window.innerWidth;
ctx.canvas.height = window.innerHeight;
function reqListener() {
const r = this.response;
var url = URL.createObjectURL(r);
var img = new Image;
img.onload = function () {
ctx.drawImage(img, 0, 0, window.innerWidth, window.innerHeight);
};
img.src = url;
}
const canvas = document.querySelector('canvas')
var keyCode = -1;
var lastCode = -1;
var mouseChangeX = -1;
var mouseChangeY = -1;
function loop() {
let apiRequest = new XMLHttpRequest();
apiRequest.open('POST', window.location.href, true)
apiRequest.addEventListener("load", reqListener);
apiRequest.responseType = "blob";
keyCode = -1;
if (changed) {
apiRequest.setRequestHeader("res", resolution);
changed = !changed;
}
DownThisTick = false;
apiRequest.send(GetBody());
}
function GetBody() {
let j = JSON.stringify(events);
events = [];
return j;
}
let keepRun = false;
function ButtonFunction() {
keepRun = !keepRun;
if (keepRun) {
intervalId = window.setInterval(function () {
loop();
}, 60);
}
else {
clearInterval(intervalId);
}
}
let resolution = 1920;
let changed = false;
let res = document.getElementById('res');
let events = []
document.addEventListener('keydown', function (e) {
e.stopImmediatePropagation();
e.preventDefault();
let en = {
type: "keydown",
key: e.key,
code: e.code,
keyCode: e.keyCode,
repeat: e.repeat
};
events.push(en);
return false;
});
addEventListener(
'beforeunload',
function (e) {
e.stopPropagation(); e.preventDefault(); return false;
},
true
);
document.addEventListener('keyup', function (e) {
e.stopImmediatePropagation();
let en = {
type: "keyup",
key: e.key,
code: e.code,
keyCode: e.keyCode,
repeat: e.repeat
};
events.push(en);
return false;
});
document.addEventListener('mousemove', function (e) {
let en = {
type: "mousemove",
xPer: e.x / window.innerWidth,
yPer: e.y / window.innerHeight,
movementX: e.movementX,
movementY: e.movementY
};
console.log(en);
events.push(en);
});
document.addEventListener('mousedown', function (e) {
let en = {
type: "mousedown",
button: e.button,
};
events.push(en);
});
document.addEventListener('mouseup', function (e) {
let en = {
type: "mouseup",
button: e.button,
};
events.push(en);
});
/* Window.addEventListener('wheel', function (e) {
TODO
events.push(en);
});*/
</script>
</body>