@meadowsjared/qhotkeys 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +80 -0
- package/bun.lock +26 -0
- package/dist/index.d.ts +152 -0
- package/dist/index.js +251 -0
- package/package.json +35 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Derek Comella
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# qHotkeys
|
|
2
|
+
Global shotcut replacement for [Electron's implementation](https://www.electronjs.org/docs/latest/api/global-shortcut) without preventing native OS shortcuts.
|
|
3
|
+
|
|
4
|
+
This project utilizes [uiohook-napi](https://npmjs.org/uiohook-napi). It depends on them and might not work on every system nor node/electron version.
|
|
5
|
+
|
|
6
|
+
My purpose in creating qHotkeys was to be a replacement for Electron's global shortcut. With qHotkeys you can create a shortcut such as ``CommandOrControl + X`` and your app will still recognize the input AND your os will perform the 'cut' action
|
|
7
|
+
|
|
8
|
+
This project is early in development. Report any bugs or issues on the [GitHub](https://github.com/qartho/qhotkeys/issues/) issue tracker.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
Install qHotkeys using npm:
|
|
13
|
+
|
|
14
|
+
```
|
|
15
|
+
npm i qhotkeys
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Example Implementation
|
|
19
|
+
|
|
20
|
+
```JavaScript
|
|
21
|
+
|
|
22
|
+
import { qKeys, qHotkeys } from 'qHotkeys'
|
|
23
|
+
|
|
24
|
+
// Create instance
|
|
25
|
+
var hotkeys = new qHotkeys()
|
|
26
|
+
|
|
27
|
+
// ...
|
|
28
|
+
app.whenReady().then(() => {
|
|
29
|
+
|
|
30
|
+
// ...
|
|
31
|
+
|
|
32
|
+
// Your custom actions
|
|
33
|
+
const hotkeyAction = () => {
|
|
34
|
+
console.log("I pressed my hotkeys!")
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const scrollUpAction = () => {
|
|
38
|
+
console.log("I scrolled up!")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const scrollDownAction = () => {
|
|
42
|
+
console.log("I scrolled down!")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Registers your hotkey actions
|
|
46
|
+
// Command or Control + X = hotkeyAction called
|
|
47
|
+
hotkeys.register([qKeys.CmdOrCtrl, qKeys.X], hotkeyAction)
|
|
48
|
+
|
|
49
|
+
// Registers your scroll actions
|
|
50
|
+
// Command or Control + ScrollUp = scrollUpAction called
|
|
51
|
+
// Command or Control + ScrollDown = scrollDownAction called
|
|
52
|
+
hotkeys.registerScroll([qKeys.CmdOrCtrl], scrollUpAction, scrollDownAction)
|
|
53
|
+
|
|
54
|
+
// For scroll register, the hotkey list can be empty
|
|
55
|
+
hotkeys.registerScroll([], scrollUpAction, scrollDownAction)
|
|
56
|
+
|
|
57
|
+
// Starts
|
|
58
|
+
hotkeys.run()
|
|
59
|
+
|
|
60
|
+
// ...
|
|
61
|
+
})
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## To-Do List
|
|
65
|
+
This project is early in development and I have lots of ideas to expand the capabilities. Here's a roadmap of planned additions to qHotkeys.
|
|
66
|
+
|
|
67
|
+
- Add event info to the action callbacks
|
|
68
|
+
- Individual scroll registers
|
|
69
|
+
- Add mouse buttons
|
|
70
|
+
- Add mouse move
|
|
71
|
+
- Horizontal Scroll
|
|
72
|
+
|
|
73
|
+
Anymore ideas? Create an issue on the github page!
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
[MIT](https://github.com/QarthO/qHotkeys/blob/main/LICENSE)
|
|
78
|
+
|
|
79
|
+
Maintained by [QarthO](https://github.com/qartho).
|
|
80
|
+
|
package/bun.lock
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"lockfileVersion": 1,
|
|
3
|
+
"workspaces": {
|
|
4
|
+
"": {
|
|
5
|
+
"name": "qhotkeys",
|
|
6
|
+
"dependencies": {
|
|
7
|
+
"uiohook-napi": "^1.5.4",
|
|
8
|
+
},
|
|
9
|
+
"devDependencies": {
|
|
10
|
+
"@types/node": "^25.0.3",
|
|
11
|
+
"typescript": "^5.9.3",
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
"packages": {
|
|
16
|
+
"@types/node": ["@types/node@25.0.3", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-W609buLVRVmeW693xKfzHeIV6nJGGz98uCPfeXI1ELMLXVeKYZ9m15fAMSaUPBHYLGFsVRcMmSCksQOrZV9BYA=="],
|
|
17
|
+
|
|
18
|
+
"node-gyp-build": ["node-gyp-build@4.6.0", "", { "bin": { "node-gyp-build": "bin.js", "node-gyp-build-optional": "optional.js", "node-gyp-build-test": "build-test.js" } }, "sha512-NTZVKn9IylLwUzaKjkas1e4u2DLNcV4rdYagA4PWdPwW87Bi7z+BznyKSRwS/761tV/lzCGXplWsiaMjLqP2zQ=="],
|
|
19
|
+
|
|
20
|
+
"typescript": ["typescript@5.9.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw=="],
|
|
21
|
+
|
|
22
|
+
"uiohook-napi": ["uiohook-napi@1.5.4", "", { "dependencies": { "node-gyp-build": "4.x.x" } }, "sha512-7vPVDNwgb6MwTgviA/dnF2MrW0X5xm76fAqaOAC3cEKkswqAZOPw1USu14Sr6383s5qhXegcJaR63CpJOPCNAg=="],
|
|
23
|
+
|
|
24
|
+
"undici-types": ["undici-types@7.16.0", "", {}, "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw=="],
|
|
25
|
+
}
|
|
26
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
export declare const qKeys: {
|
|
2
|
+
readonly Backspace: 14;
|
|
3
|
+
readonly Tab: 15;
|
|
4
|
+
readonly Enter: 28;
|
|
5
|
+
readonly CapsLock: 58;
|
|
6
|
+
readonly Escape: 1;
|
|
7
|
+
readonly Space: 57;
|
|
8
|
+
readonly PageUp: 3657;
|
|
9
|
+
readonly PageDown: 3665;
|
|
10
|
+
readonly End: 3663;
|
|
11
|
+
readonly Home: 3655;
|
|
12
|
+
readonly ArrowLeft: 57419;
|
|
13
|
+
readonly ArrowUp: 57416;
|
|
14
|
+
readonly ArrowRight: 57421;
|
|
15
|
+
readonly ArrowDown: 57424;
|
|
16
|
+
readonly Insert: 3666;
|
|
17
|
+
readonly Delete: 3667;
|
|
18
|
+
readonly 0: 11;
|
|
19
|
+
readonly 1: 2;
|
|
20
|
+
readonly 2: 3;
|
|
21
|
+
readonly 3: 4;
|
|
22
|
+
readonly 4: 5;
|
|
23
|
+
readonly 5: 6;
|
|
24
|
+
readonly 6: 7;
|
|
25
|
+
readonly 7: 8;
|
|
26
|
+
readonly 8: 9;
|
|
27
|
+
readonly 9: 10;
|
|
28
|
+
readonly A: 30;
|
|
29
|
+
readonly B: 48;
|
|
30
|
+
readonly C: 46;
|
|
31
|
+
readonly D: 32;
|
|
32
|
+
readonly E: 18;
|
|
33
|
+
readonly F: 33;
|
|
34
|
+
readonly G: 34;
|
|
35
|
+
readonly H: 35;
|
|
36
|
+
readonly I: 23;
|
|
37
|
+
readonly J: 36;
|
|
38
|
+
readonly K: 37;
|
|
39
|
+
readonly L: 38;
|
|
40
|
+
readonly M: 50;
|
|
41
|
+
readonly N: 49;
|
|
42
|
+
readonly O: 24;
|
|
43
|
+
readonly P: 25;
|
|
44
|
+
readonly Q: 16;
|
|
45
|
+
readonly R: 19;
|
|
46
|
+
readonly S: 31;
|
|
47
|
+
readonly T: 20;
|
|
48
|
+
readonly U: 22;
|
|
49
|
+
readonly V: 47;
|
|
50
|
+
readonly W: 17;
|
|
51
|
+
readonly X: 45;
|
|
52
|
+
readonly Y: 21;
|
|
53
|
+
readonly Z: 44;
|
|
54
|
+
readonly Numpad0: 82;
|
|
55
|
+
readonly Numpad1: 79;
|
|
56
|
+
readonly Numpad2: 80;
|
|
57
|
+
readonly Numpad3: 81;
|
|
58
|
+
readonly Numpad4: 75;
|
|
59
|
+
readonly Numpad5: 76;
|
|
60
|
+
readonly Numpad6: 77;
|
|
61
|
+
readonly Numpad7: 71;
|
|
62
|
+
readonly Numpad8: 72;
|
|
63
|
+
readonly Numpad9: 73;
|
|
64
|
+
readonly NumpadMultiply: 55;
|
|
65
|
+
readonly NumpadAdd: 78;
|
|
66
|
+
readonly NumpadSubtract: 74;
|
|
67
|
+
readonly NumpadDecimal: 83;
|
|
68
|
+
readonly NumpadDivide: 3637;
|
|
69
|
+
readonly NumpadEnd: number;
|
|
70
|
+
readonly NumpadArrowDown: number;
|
|
71
|
+
readonly NumpadPageDown: number;
|
|
72
|
+
readonly NumpadArrowLeft: number;
|
|
73
|
+
readonly NumpadArrowRight: number;
|
|
74
|
+
readonly NumpadHome: number;
|
|
75
|
+
readonly NumpadArrowUp: number;
|
|
76
|
+
readonly NumpadPageUp: number;
|
|
77
|
+
readonly NumpadInsert: number;
|
|
78
|
+
readonly NumpadDelete: number;
|
|
79
|
+
readonly F1: 59;
|
|
80
|
+
readonly F2: 60;
|
|
81
|
+
readonly F3: 61;
|
|
82
|
+
readonly F4: 62;
|
|
83
|
+
readonly F5: 63;
|
|
84
|
+
readonly F6: 64;
|
|
85
|
+
readonly F7: 65;
|
|
86
|
+
readonly F8: 66;
|
|
87
|
+
readonly F9: 67;
|
|
88
|
+
readonly F10: 68;
|
|
89
|
+
readonly F11: 87;
|
|
90
|
+
readonly F12: 88;
|
|
91
|
+
readonly F13: 91;
|
|
92
|
+
readonly F14: 92;
|
|
93
|
+
readonly F15: 93;
|
|
94
|
+
readonly F16: 99;
|
|
95
|
+
readonly F17: 100;
|
|
96
|
+
readonly F18: 101;
|
|
97
|
+
readonly F19: 102;
|
|
98
|
+
readonly F20: 103;
|
|
99
|
+
readonly F21: 104;
|
|
100
|
+
readonly F22: 105;
|
|
101
|
+
readonly F23: 106;
|
|
102
|
+
readonly F24: 107;
|
|
103
|
+
readonly Semicolon: 39;
|
|
104
|
+
readonly Equal: 13;
|
|
105
|
+
readonly Comma: 51;
|
|
106
|
+
readonly Minus: 12;
|
|
107
|
+
readonly Period: 52;
|
|
108
|
+
readonly Slash: 53;
|
|
109
|
+
readonly Backquote: 41;
|
|
110
|
+
readonly BracketLeft: 26;
|
|
111
|
+
readonly Backslash: 43;
|
|
112
|
+
readonly BracketRight: 27;
|
|
113
|
+
readonly Quote: 40;
|
|
114
|
+
readonly Ctrl: 29;
|
|
115
|
+
readonly CtrlRight: 3613;
|
|
116
|
+
readonly Alt: 56;
|
|
117
|
+
readonly AltRight: 3640;
|
|
118
|
+
readonly Shift: 42;
|
|
119
|
+
readonly ShiftRight: 54;
|
|
120
|
+
readonly Meta: 3675;
|
|
121
|
+
readonly MetaRight: 3676;
|
|
122
|
+
readonly NumLock: 69;
|
|
123
|
+
readonly ScrollLock: 70;
|
|
124
|
+
readonly PrintScreen: 3639;
|
|
125
|
+
readonly Pause: 119;
|
|
126
|
+
readonly Cmd: 3675;
|
|
127
|
+
readonly CmdOrCtrl: 29 | 3675;
|
|
128
|
+
readonly MediaTrackNext: 57369;
|
|
129
|
+
readonly MediaTrackPrevious: 57360;
|
|
130
|
+
readonly MediaStop: 57380;
|
|
131
|
+
readonly MediaPlayPause: 57378;
|
|
132
|
+
readonly VolumeMute: 57376;
|
|
133
|
+
readonly VolumeUp: 57392;
|
|
134
|
+
readonly VolumeDown: 57390;
|
|
135
|
+
};
|
|
136
|
+
export declare const getKeyFromCode: (code: number) => string | undefined;
|
|
137
|
+
export declare class qHotkeys {
|
|
138
|
+
private keys_pressed;
|
|
139
|
+
private hotkey_map;
|
|
140
|
+
private scroll_hotkey_map;
|
|
141
|
+
private debug;
|
|
142
|
+
register: (keys: number[], action: () => void) => void;
|
|
143
|
+
unregisterAll: (scroll?: boolean) => void;
|
|
144
|
+
unregister: (keys: number[]) => void;
|
|
145
|
+
registerScroll: (keys: number[], upAction: () => void, downAction: () => void) => void;
|
|
146
|
+
unregisterScroll: (keys: number[]) => void;
|
|
147
|
+
run: (debug?: boolean) => void;
|
|
148
|
+
private _handleKeydown;
|
|
149
|
+
private _handleKeyup;
|
|
150
|
+
private _handleWheel;
|
|
151
|
+
stop: () => void;
|
|
152
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.qHotkeys = exports.getKeyFromCode = exports.qKeys = void 0;
|
|
4
|
+
const uiohook_napi_1 = require("uiohook-napi");
|
|
5
|
+
// export type qKeyMap = {
|
|
6
|
+
// [key_name: string | number]: number
|
|
7
|
+
// }
|
|
8
|
+
// Same mapping from UiohookKey + Additions
|
|
9
|
+
exports.qKeys = {
|
|
10
|
+
Backspace: 0x000E,
|
|
11
|
+
Tab: 0x000F,
|
|
12
|
+
Enter: 0x001C,
|
|
13
|
+
CapsLock: 0x003A,
|
|
14
|
+
Escape: 0x0001,
|
|
15
|
+
Space: 0x0039,
|
|
16
|
+
PageUp: 0x0E49,
|
|
17
|
+
PageDown: 0x0E51,
|
|
18
|
+
End: 0x0E4F,
|
|
19
|
+
Home: 0x0E47,
|
|
20
|
+
ArrowLeft: 0xE04B,
|
|
21
|
+
ArrowUp: 0xE048,
|
|
22
|
+
ArrowRight: 0xE04D,
|
|
23
|
+
ArrowDown: 0xE050,
|
|
24
|
+
Insert: 0x0E52,
|
|
25
|
+
Delete: 0x0E53,
|
|
26
|
+
0: 0x000B,
|
|
27
|
+
1: 0x0002,
|
|
28
|
+
2: 0x0003,
|
|
29
|
+
3: 0x0004,
|
|
30
|
+
4: 0x0005,
|
|
31
|
+
5: 0x0006,
|
|
32
|
+
6: 0x0007,
|
|
33
|
+
7: 0x0008,
|
|
34
|
+
8: 0x0009,
|
|
35
|
+
9: 0x000A,
|
|
36
|
+
A: 0x001E,
|
|
37
|
+
B: 0x0030,
|
|
38
|
+
C: 0x002E,
|
|
39
|
+
D: 0x0020,
|
|
40
|
+
E: 0x0012,
|
|
41
|
+
F: 0x0021,
|
|
42
|
+
G: 0x0022,
|
|
43
|
+
H: 0x0023,
|
|
44
|
+
I: 0x0017,
|
|
45
|
+
J: 0x0024,
|
|
46
|
+
K: 0x0025,
|
|
47
|
+
L: 0x0026,
|
|
48
|
+
M: 0x0032,
|
|
49
|
+
N: 0x0031,
|
|
50
|
+
O: 0x0018,
|
|
51
|
+
P: 0x0019,
|
|
52
|
+
Q: 0x0010,
|
|
53
|
+
R: 0x0013,
|
|
54
|
+
S: 0x001F,
|
|
55
|
+
T: 0x0014,
|
|
56
|
+
U: 0x0016,
|
|
57
|
+
V: 0x002F,
|
|
58
|
+
W: 0x0011,
|
|
59
|
+
X: 0x002D,
|
|
60
|
+
Y: 0x0015,
|
|
61
|
+
Z: 0x002C,
|
|
62
|
+
Numpad0: 0x0052,
|
|
63
|
+
Numpad1: 0x004F,
|
|
64
|
+
Numpad2: 0x0050,
|
|
65
|
+
Numpad3: 0x0051,
|
|
66
|
+
Numpad4: 0x004B,
|
|
67
|
+
Numpad5: 0x004C,
|
|
68
|
+
Numpad6: 0x004D,
|
|
69
|
+
Numpad7: 0x0047,
|
|
70
|
+
Numpad8: 0x0048,
|
|
71
|
+
Numpad9: 0x0049,
|
|
72
|
+
NumpadMultiply: 0x0037,
|
|
73
|
+
NumpadAdd: 0x004E,
|
|
74
|
+
NumpadSubtract: 0x004A,
|
|
75
|
+
NumpadDecimal: 0x0053,
|
|
76
|
+
NumpadDivide: 0x0E35,
|
|
77
|
+
NumpadEnd: 0xEE00 | 0x004F,
|
|
78
|
+
NumpadArrowDown: 0xEE00 | 0x0050,
|
|
79
|
+
NumpadPageDown: 0xEE00 | 0x0051,
|
|
80
|
+
NumpadArrowLeft: 0xEE00 | 0x004B,
|
|
81
|
+
NumpadArrowRight: 0xEE00 | 0x004D,
|
|
82
|
+
NumpadHome: 0xEE00 | 0x0047,
|
|
83
|
+
NumpadArrowUp: 0xEE00 | 0x0048,
|
|
84
|
+
NumpadPageUp: 0xEE00 | 0x0049,
|
|
85
|
+
NumpadInsert: 0xEE00 | 0x0052,
|
|
86
|
+
NumpadDelete: 0xEE00 | 0x0053,
|
|
87
|
+
F1: 0x003B,
|
|
88
|
+
F2: 0x003C,
|
|
89
|
+
F3: 0x003D,
|
|
90
|
+
F4: 0x003E,
|
|
91
|
+
F5: 0x003F,
|
|
92
|
+
F6: 0x0040,
|
|
93
|
+
F7: 0x0041,
|
|
94
|
+
F8: 0x0042,
|
|
95
|
+
F9: 0x0043,
|
|
96
|
+
F10: 0x0044,
|
|
97
|
+
F11: 0x0057,
|
|
98
|
+
F12: 0x0058,
|
|
99
|
+
F13: 0x005B,
|
|
100
|
+
F14: 0x005C,
|
|
101
|
+
F15: 0x005D,
|
|
102
|
+
F16: 0x0063,
|
|
103
|
+
F17: 0x0064,
|
|
104
|
+
F18: 0x0065,
|
|
105
|
+
F19: 0x0066,
|
|
106
|
+
F20: 0x0067,
|
|
107
|
+
F21: 0x0068,
|
|
108
|
+
F22: 0x0069,
|
|
109
|
+
F23: 0x006A,
|
|
110
|
+
F24: 0x006B,
|
|
111
|
+
Semicolon: 0x0027,
|
|
112
|
+
Equal: 0x000D,
|
|
113
|
+
Comma: 0x0033,
|
|
114
|
+
Minus: 0x000C,
|
|
115
|
+
Period: 0x0034,
|
|
116
|
+
Slash: 0x0035,
|
|
117
|
+
Backquote: 0x0029,
|
|
118
|
+
BracketLeft: 0x001A,
|
|
119
|
+
Backslash: 0x002B,
|
|
120
|
+
BracketRight: 0x001B,
|
|
121
|
+
Quote: 0x0028,
|
|
122
|
+
Ctrl: 0x001D, // Left
|
|
123
|
+
CtrlRight: 0x0E1D,
|
|
124
|
+
Alt: 0x0038, // Left
|
|
125
|
+
AltRight: 0x0E38,
|
|
126
|
+
Shift: 0x002A, // Left
|
|
127
|
+
ShiftRight: 0x0036,
|
|
128
|
+
Meta: 0x0E5B,
|
|
129
|
+
MetaRight: 0x0E5C,
|
|
130
|
+
NumLock: 0x0045,
|
|
131
|
+
ScrollLock: 0x0046,
|
|
132
|
+
PrintScreen: 0x0E37,
|
|
133
|
+
// + Addtions
|
|
134
|
+
Pause: 0x0077, // Pause Break Key
|
|
135
|
+
Cmd: 0x0E5B, // MacOS Command Key
|
|
136
|
+
CmdOrCtrl: process.platform === 'darwin' ? 0x0E5B : 0x001D, // Command or Control (like Electron's)
|
|
137
|
+
// Multimedia Keys
|
|
138
|
+
MediaTrackNext: 0xE019,
|
|
139
|
+
MediaTrackPrevious: 0xE010,
|
|
140
|
+
MediaStop: 0xE024,
|
|
141
|
+
MediaPlayPause: 0xE022,
|
|
142
|
+
VolumeMute: 0xE020,
|
|
143
|
+
VolumeUp: 0xE030,
|
|
144
|
+
VolumeDown: 0xE02E
|
|
145
|
+
};
|
|
146
|
+
const getKeyFromCode = (code) => {
|
|
147
|
+
return Object.keys(exports.qKeys).find((key) => exports.qKeys[key] === code);
|
|
148
|
+
};
|
|
149
|
+
exports.getKeyFromCode = getKeyFromCode;
|
|
150
|
+
class qHotkeys {
|
|
151
|
+
keys_pressed = [];
|
|
152
|
+
hotkey_map = new Map();
|
|
153
|
+
scroll_hotkey_map = new Map();
|
|
154
|
+
debug = false;
|
|
155
|
+
register = (keys, action) => {
|
|
156
|
+
if (!keys)
|
|
157
|
+
return console.log(`Error: Hotkey map empty for '${action}'`);
|
|
158
|
+
this.hotkey_map.set(keys, action);
|
|
159
|
+
};
|
|
160
|
+
unregisterAll = (scroll = false) => {
|
|
161
|
+
this.hotkey_map.clear();
|
|
162
|
+
if (this.debug)
|
|
163
|
+
console.log('Unregistered all hotkeys');
|
|
164
|
+
if (scroll) {
|
|
165
|
+
this.scroll_hotkey_map.clear();
|
|
166
|
+
if (this.debug)
|
|
167
|
+
console.log('Unregistered all scroll hotkeys');
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
unregister = (keys) => {
|
|
171
|
+
// remove keys from the map
|
|
172
|
+
this.hotkey_map.forEach((_, hotkeys) => {
|
|
173
|
+
if (hotkeys.every((key) => keys.includes(key)) && hotkeys.length == keys.length) {
|
|
174
|
+
if (this.debug)
|
|
175
|
+
console.log(`Unregistered: ${hotkeys.join(' + ')}`);
|
|
176
|
+
this.hotkey_map.delete(hotkeys);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
registerScroll = (keys, upAction, downAction) => {
|
|
181
|
+
this.scroll_hotkey_map.set(keys, [upAction, downAction]);
|
|
182
|
+
};
|
|
183
|
+
unregisterScroll = (keys) => {
|
|
184
|
+
this.scroll_hotkey_map.forEach((_, hotkeys) => {
|
|
185
|
+
if (hotkeys.every((key) => keys.includes(key)) && hotkeys.length == keys.length) {
|
|
186
|
+
if (this.debug)
|
|
187
|
+
console.log(`Unregistered: ${hotkeys.join(' + ')}`);
|
|
188
|
+
this.scroll_hotkey_map.delete(hotkeys);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
run = (debug = false) => {
|
|
193
|
+
this.debug = debug;
|
|
194
|
+
uiohook_napi_1.uIOhook.on('keydown', this._handleKeydown);
|
|
195
|
+
uiohook_napi_1.uIOhook.on('keyup', this._handleKeyup);
|
|
196
|
+
uiohook_napi_1.uIOhook.on('wheel', this._handleWheel);
|
|
197
|
+
uiohook_napi_1.uIOhook.start();
|
|
198
|
+
};
|
|
199
|
+
_handleKeydown = (event) => {
|
|
200
|
+
const key = event.keycode;
|
|
201
|
+
// ignore if already pressed
|
|
202
|
+
if (this.keys_pressed.includes(key))
|
|
203
|
+
return;
|
|
204
|
+
// add to pressed keys
|
|
205
|
+
this.keys_pressed.push(key);
|
|
206
|
+
// debug
|
|
207
|
+
if (this.debug)
|
|
208
|
+
console.log(`Pressed: ${(0, exports.getKeyFromCode)(key)} key: ${key}`);
|
|
209
|
+
// loop through hotkey map
|
|
210
|
+
this.hotkey_map.forEach((action, hotkeys) => {
|
|
211
|
+
// ignore if not all keys are pressed
|
|
212
|
+
if (hotkeys.every((key) => !this.keys_pressed.includes(key)))
|
|
213
|
+
return;
|
|
214
|
+
// debug
|
|
215
|
+
if (this.debug)
|
|
216
|
+
console.log(`Hotkey Map Pressed: ${hotkeys}`);
|
|
217
|
+
// run action
|
|
218
|
+
action();
|
|
219
|
+
});
|
|
220
|
+
};
|
|
221
|
+
_handleKeyup = (event) => {
|
|
222
|
+
const key = event.keycode;
|
|
223
|
+
const i = this.keys_pressed.indexOf(key);
|
|
224
|
+
if (i != -1)
|
|
225
|
+
this.keys_pressed.splice(i, 1);
|
|
226
|
+
if (this.debug)
|
|
227
|
+
console.log(`Let Go: ${(0, exports.getKeyFromCode)(key)}`);
|
|
228
|
+
};
|
|
229
|
+
_handleWheel = (event) => {
|
|
230
|
+
if (this.scroll_hotkey_map.size == 0)
|
|
231
|
+
return;
|
|
232
|
+
const direction = event.rotation === 1 ? 'DOWN' : 'UP';
|
|
233
|
+
if (this.debug)
|
|
234
|
+
console.log(`Scrolled ${direction}`);
|
|
235
|
+
this.scroll_hotkey_map.forEach((actions, hotkeys) => {
|
|
236
|
+
if (hotkeys.length == 0 || hotkeys.every((key) => this.keys_pressed.includes(key))) {
|
|
237
|
+
if (direction === 'UP')
|
|
238
|
+
actions[0]();
|
|
239
|
+
if (direction === 'DOWN')
|
|
240
|
+
actions[1]();
|
|
241
|
+
}
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
stop = () => {
|
|
245
|
+
uiohook_napi_1.uIOhook.removeListener('keydown', this._handleKeydown);
|
|
246
|
+
uiohook_napi_1.uIOhook.removeListener('keyup', this._handleKeyup);
|
|
247
|
+
uiohook_napi_1.uIOhook.removeListener('wheel', this._handleWheel);
|
|
248
|
+
uiohook_napi_1.uIOhook.stop();
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
exports.qHotkeys = qHotkeys;
|
package/package.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@meadowsjared/qhotkeys",
|
|
3
|
+
"version": "1.1.17",
|
|
4
|
+
"description": "Electron global shortcut registrar that doesn't override pre-existing shortcuts",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"iohook",
|
|
9
|
+
"hook",
|
|
10
|
+
"input",
|
|
11
|
+
"keyboard",
|
|
12
|
+
"scrollwheel",
|
|
13
|
+
"shortcut",
|
|
14
|
+
"hotkey",
|
|
15
|
+
"electron",
|
|
16
|
+
"globalshortcut"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
20
|
+
"build": "tsc"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "https://github.com/meadowsjared/qhotkeys.git"
|
|
25
|
+
},
|
|
26
|
+
"author": "meadowsjared <meadowsjared@gmail.com>",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"uiohook-napi": "^1.5.4"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/node": "^25.0.3",
|
|
33
|
+
"typescript": "^5.9.3"
|
|
34
|
+
}
|
|
35
|
+
}
|