qdesk 1.0.4 → 1.0.6
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/dist/chord-utils.js +17 -12
- package/dist/index.js +7 -0
- package/dist/koffi-utils.js +7 -0
- package/package.json +1 -1
package/dist/chord-utils.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallNextHookEx, decodeKeyboardHookLParam, DispatchMessageW, GetAsyncKeyState,
|
|
1
|
+
import { CallNextHookEx, decodeKeyboardHookLParam, DispatchMessageW, GetAsyncKeyState, GetModuleHandleW, PeekMessageW, registerKeyboardHookCallback, SetWindowsHookExW, TranslateMessage, UnhookWindowsHookEx, unregisterCallback, } from "./koffi-utils.js";
|
|
2
2
|
const process = globalThis.process;
|
|
3
3
|
const MOD_ALT = 0x0001;
|
|
4
4
|
const MOD_CONTROL = 0x0002;
|
|
@@ -14,6 +14,7 @@ const HC_ACTION = 0;
|
|
|
14
14
|
const WH_KEYBOARD_LL = 13;
|
|
15
15
|
const WM_KEYDOWN = 0x0100;
|
|
16
16
|
const WM_SYSKEYDOWN = 0x0104;
|
|
17
|
+
const PM_REMOVE = 0x0001;
|
|
17
18
|
export function normalizeChord(chord) {
|
|
18
19
|
const parts = chord
|
|
19
20
|
.split("+")
|
|
@@ -155,6 +156,8 @@ export function startListening(options) {
|
|
|
155
156
|
}
|
|
156
157
|
let keyboardHook = null;
|
|
157
158
|
let keyboardHookProcPtr = null;
|
|
159
|
+
let messagePump;
|
|
160
|
+
let isShuttingDown = false;
|
|
158
161
|
const callback = (nCode, wParam, lParam) => {
|
|
159
162
|
const passThrough = () => BigInt(Number(CallNextHookEx(keyboardHook, nCode, wParam, lParam)));
|
|
160
163
|
try {
|
|
@@ -206,7 +209,15 @@ export function startListening(options) {
|
|
|
206
209
|
process.exit(1);
|
|
207
210
|
}
|
|
208
211
|
function shutdown() {
|
|
212
|
+
if (isShuttingDown) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
isShuttingDown = true;
|
|
209
216
|
console.log("\n[qdesk] Shutting down...");
|
|
217
|
+
if (messagePump) {
|
|
218
|
+
clearInterval(messagePump);
|
|
219
|
+
messagePump = undefined;
|
|
220
|
+
}
|
|
210
221
|
if (keyboardHook) {
|
|
211
222
|
UnhookWindowsHookEx(keyboardHook);
|
|
212
223
|
keyboardHook = null;
|
|
@@ -222,18 +233,12 @@ export function startListening(options) {
|
|
|
222
233
|
return {
|
|
223
234
|
runMessageLoop: () => {
|
|
224
235
|
const msg = {};
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
236
|
+
messagePump = setInterval(() => {
|
|
237
|
+
while (Number(PeekMessageW(msg, null, 0, 0, PM_REMOVE)) !== 0) {
|
|
238
|
+
TranslateMessage(msg);
|
|
239
|
+
DispatchMessageW(msg);
|
|
229
240
|
}
|
|
230
|
-
|
|
231
|
-
console.error("[error] GetMessageW returned -1");
|
|
232
|
-
break;
|
|
233
|
-
}
|
|
234
|
-
TranslateMessage(msg);
|
|
235
|
-
DispatchMessageW(msg);
|
|
236
|
-
}
|
|
241
|
+
}, 8);
|
|
237
242
|
},
|
|
238
243
|
};
|
|
239
244
|
}
|
package/dist/index.js
CHANGED
|
@@ -20,10 +20,17 @@ function getPackageVersion() {
|
|
|
20
20
|
return "unknown";
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
|
+
function setTerminalTitle(title) {
|
|
24
|
+
process.title = title;
|
|
25
|
+
if (process.stdout.isTTY) {
|
|
26
|
+
process.stdout.write(`\u001b]0;${title}\u0007`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
23
29
|
if (hasCliFlag("--version") || hasCliFlag("-v")) {
|
|
24
30
|
console.log(getPackageVersion());
|
|
25
31
|
process.exit(0);
|
|
26
32
|
}
|
|
33
|
+
setTerminalTitle("qdesk");
|
|
27
34
|
function normalizeChordInput(chord) {
|
|
28
35
|
return normalizeChord(chord.trim().toLowerCase());
|
|
29
36
|
}
|
package/dist/koffi-utils.js
CHANGED
|
@@ -53,6 +53,13 @@ export const GetMessageW = user32.func("GetMessageW", "int", [
|
|
|
53
53
|
UINT,
|
|
54
54
|
UINT,
|
|
55
55
|
]);
|
|
56
|
+
export const PeekMessageW = user32.func("PeekMessageW", "int", [
|
|
57
|
+
koffi.out(koffi.pointer(MSG)),
|
|
58
|
+
HWND,
|
|
59
|
+
UINT,
|
|
60
|
+
UINT,
|
|
61
|
+
UINT,
|
|
62
|
+
]);
|
|
56
63
|
export const TranslateMessage = user32.func("TranslateMessage", "int", [
|
|
57
64
|
koffi.pointer(MSG),
|
|
58
65
|
]);
|