-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (54 loc) · 1.42 KB
/
index.js
File metadata and controls
63 lines (54 loc) · 1.42 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
const cp = require("child_process");
const io = require("socket.io")();
var bash = cp.spawn("bash");
io.on("connection", socket => {
console.log("client connected");
socket.on("m", (x, y) => {
/// mouseMoveRelative(x, y);
bash.stdin.write(`xdotool mousemove_relative -- ${x} ${y}\n`);
});
socket.on("d", bmask => {
mouseDown(bmask);
});
socket.on("c", bmask => {
mouseClick(bmask);
});
});
io.listen(3000);
/*
global.x = 0;
global.y = 0;
const mouseMoveInterval = 32;
global.mouseMoveIntervalFunction = null;
function callMouseMove() {
if (x !== 0 || y !== 0) {
// console.log(x, y);
bash.stdin.write(`xdotool mousemove_relative -- ${x} ${y}\n`);
x = y = 0;
}
mouseMoveIntervalFunction = null;
}
function mouseMoveRelative(x, y) {
global.x += x;
global.y += y;
// bash.stdin.write(`xdotool mousemove_relative -- ${x} ${y}\n`);
//if ( mouseMoveIntervalFunction === null ){
// mouseMoveIntervalFunction = setTimeout(callMouseMove, mouseMoveInterval);
//}
}
*/
bash.on("error", function(code) {
console.log("error with code " + code);
});
bash.on("close", function(code) {
console.log("closed with code " + code);
});
bash.on("exit", function(code) {
console.log("exited with code " + code);
});
function mouseDown(bmask) {
bash.stdin.write(`xdotool mousedown ${bmask}\n`);
}
function mouseClick(bmask) {
bash.stdin.write(`xdotool click ${bmask} && xdotool mouseup ${bmask}\n`);
}