-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (68 loc) · 1.89 KB
/
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
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
class ShortcutHelper {
constructor() {
var binary = require('node-pre-gyp');
var path = require('path');
var binding_path = binary.find(path.resolve(path.join(__dirname, '.package.json')));
this.impl = require(binding_path);
if (process.platform === 'darwin') {
this.macImpl = require(binding_path);
}
}
start(enableLogger) {
return this.impl.start(enableLogger);
}
stop() {
return this.impl.stop();
}
reload() {
this.impl.unregisterAllShortcuts();
this.impl.stop();
this.impl.start(false);
}
registerShortcut(keys, callback, releaseCallback, keysAreVKC) {
return this.impl.registerShortcut(keys, callback, releaseCallback, keysAreVKC);
}
unregisterShortcut(shortcutId) {
return this.impl.unregisterShortcut(shortcutId);
}
collectPressedKeyCodes() {
console.log('\r\n(DHK) looking for pressed keys');
if (process.platform === 'win32') {
throw new TypeError('win32 impl does not track the keys');
}
this.impl.collectPressedKeyCodes(true);
}
stopCollectingKeys() {
this.impl.collectPressedKeyCodes(false);
}
pressedKeyCodes() {
if (process.platform === 'win32') {
throw new TypeError('win32 impl does not track the keys');
}
const keyCodes = this.impl.pressedKeyCodes();
console.log('\r\n(DHK) Fetching the key codes [' + keyCodes + ']');
return keyCodes;
}
setupAccessibilityCallback(enable, cb) {
if (process.platform === 'darwin') {
if (enable) {
return this.macImpl.macSubscribeAccessibilityUpdates(cb);
} else {
return this.macImpl.macUnsubscribeAccessibilityUpdates();
}
}
}
showAccessibilitySettings() {
if (process.platform === 'darwin') {
this.macImpl.macShowAccessibilitySettings();
}
}
checkAccessibility() {
if (process.platform === 'darwin') {
return this.macImpl.macCheckAccessibilityGranted();
}
return true;
}
}
var shortcutHelper = new ShortcutHelper();
module.exports = shortcutHelper;