-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
39 lines (36 loc) · 1.08 KB
/
main.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
const robotjs = require('robotjs')
const InputEvent = require('input-event')
const input = new InputEvent('/dev/input/event0')
const keyboard = new InputEvent.Keyboard(input)
// keyboard.on('keyup' , console.log);
// keyboard.on('keydown' , console.log);
// keyboard.on('keypress', console.log);
let buffer, timer
keyboard.on('keydown', (x) => {
if(buffer){
if(buffer[buffer.length - 1] !== x.code)
buffer.push(x.code)
if(buffer.length > 3)
buffer = buffer.slice(1)
} else {
buffer = [x.code]
}
// 29 = ctrl, 56 = alt, 25 = p
if(timer === undefined && buffer.length === 3 && buffer[0] === 29 && buffer[1] === 56 && buffer[2] === 25) {
console.log("start")
timer = setInterval(() => {
console.log('checking');
let mouse = robotjs.getMousePos()
console.log(robotjs.getPixelColor(mouse.x, mouse.y))
}, 33)
}
console.log(timer, buffer);
})
keyboard.on('keypress', (x) => {
// If the picker is enabled and esc key is pressed
if(timer && x.code === 1) {
clearInterval(timer)
timer = undefined
buffer = undefined
}
})