-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.js
126 lines (102 loc) · 2.84 KB
/
record.js
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
var robot = require("robotjs");
const fs = require("fs");
//////////////////
// System Variables
let receivedStop = false;
let mouseArray = [];
fs.readFile("./data.json", "utf8", (err, data) => {
if (err) {
console.log(`Error reading file from disk: ${err}`);
} else {
//
// Decided Which File To Save To
const JSONData = JSON.parse(data);
JSONData.writes += 1;
// Utilize To Write
fs.writeFile("./data.json", JSON.stringify(JSONData, null, 4), (err) => {
if (err) {
console.log(`Error writing file: ${err}`);
}
console.log("data.json File Updated To " + JSONData.writes);
});
// Updated
const mouseEvents = require("global-mouse-events");
mouseEvents.on("mousedown", (event) => {
event.mouseDown = true;
// console.log(event);
mouseArray.push(event);
});
mouseEvents.on("mouseup", (event) => {
event.mouseUp = true;
// console.log(event);
mouseArray.push(event);
});
("use strict");
const ioHook = require("iohook");
ioHook.on("keydown", (event) => {
mouseArray.push(event);
console.log(event); // { type: 'mousemove', x: 700, y: 400 }
if (event.keycode === 88) {
receivedStop = true;
}
});
// Register and start hook
ioHook.start();
// Alternatively, pass true to start in DEBUG mode.
ioHook.start(true);
// False to disable DEBUG. Cleaner terminal output.
ioHook.start(false);
repeat();
async function repeat() {
if (!receivedStop) {
if (
JSON.stringify(robot.getMousePos()) !==
JSON.stringify(mouseArray[mouseArray.length - 1])
)
mouseArray.push(robot.getMousePos());
// console.log(mouseArray)
console.log(mouseArray[mouseArray.length - 1]);
fs.writeFile(
"./saves/rec" + JSONData.writes + ".json",
JSON.stringify(mouseArray, null, 4),
(err) => {
if (err) {
console.log(`Error writing file: ${err}`);
}
console.log("Saved To Rec" + JSONData.writes);
}
);
}
setTimeout(() => {
if (!receivedStop) {
repeat();
}
}, 25);
}
}
});
// // Speed up the mouse.
// robot.setMouseDelay(2);
// var twoPI = Math.PI * 2.0;
// var screenSize = robot.getScreenSize();
// var height = (screenSize.height / 2) - 10;
// var width = screenSize.width;
// for (var x = 0; x < width; x++) {
// y = height * Math.sin((twoPI * x) / width) + height;
// robot.moveMouse(x, y);
// }
// // Keyboard
// // Type "Hello World" then press enter.
// var robot = require("robotjs");
// // Type "Hello World".
// robot.typeString("Hello World");
// // Press enter.
// robot.keyTap("enter");
// // Screen
// // Get pixel color under the mouse.
// var robot = require("robotjs");
// // Get mouse position.
// var mouse = robot.getMousePos();
// // Get pixel color in hex format.
// var hex = robot.getPixelColor(mouse.x, mouse.y);
// console.log("#" + hex + " at x:" + mouse.x + " y:" + mouse.y);