-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.js
65 lines (56 loc) · 1.43 KB
/
run.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
const keylogger = require("keylogger.js")
const activities = require('./activities.json')
const transformationKeys = require('./transformationKeys.json')
const robot = require("robotjs")
let index = 0
robot.setKeyboardDelay(1)
console.log('début du script')
const intervalId = setInterval(() => {
if (index >= activities.length) {
console.log('fin du script')
clearInterval(intervalId)
keylogger.stop()
process.exit()
}
const { x, y, key, isUp } = activities[index]
keyAndClick(key, isUp)
robot.moveMouse(x, y)
index++
}, 10)
const keyAndClick = (key, isUp) => {
if (key === undefined) return
const hasClicked = click(key, isUp)
if (hasClicked === null) tap(key, isUp)
}
const click = (key, isUp) => {
let keyToTrigger = null
switch (key) {
case 'Left Click':
keyToTrigger = 'left'
break
case 'Right Click':
keyToTrigger = 'right'
break
default:
return null
}
if (!isUp) return
robot.mouseClick(keyToTrigger)
}
const tap = (key, isUp) => {
if (key === null) return
try {
const keyFounded = transformationKeys[key] === undefined ? key : transformationKeys[key]
const upOrDown = isUp ? 'up' : 'down'
robot.keyToggle(keyFounded, upOrDown)
} catch (error) {
console.log(error)
process.exit()
}
}
keylogger.start((keyPressed) => {
if (keyPressed !== 'Escape') return
robot.mouseToggle('up', 'left')
keylogger.stop()
process.exit()
})