-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (33 loc) · 928 Bytes
/
index.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
const fs = require("fs");
const { GlobalKeyboardListener } = require("node-global-key-listener");
const keys = new GlobalKeyboardListener();
const file = `/tmp/dashcam-keys.log`;
let pressed = {};
console.log(`Writing to file: ${file}`);
module.exports = () => {
keys.addListener((e, down) => {
if (e.state == "DOWN") {
pressed[e.name] = true;
let k = `Down: ${Object.keys(pressed)
.filter((e) => pressed[e])
.join(", ")}`;
console.log(k);
fs.appendFile(file, `${k}\n`, (err) => {
if (err) {
console.log(err);
}
});
} else {
pressed[e.name] = false;
}
});
new GlobalKeyboardListener({
windows: {
onError: (errorCode) => console.error("ERROR: " + errorCode),
onInfo: (info) => console.info("INFO: " + info),
},
mac: {
onError: (errorCode) => console.error("ERROR: " + errorCode),
},
});
};