simen-keyboard-listener 1.1.2 → 1.1.4
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/index.d.mts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +45 -7
- package/dist/index.mjs +41 -6
- package/package.json +6 -5
package/dist/index.d.mts
CHANGED
|
@@ -37,5 +37,32 @@ declare function createGlobalKeyboardListener(): IGlobalKeyboardListener;
|
|
|
37
37
|
declare function checkKeyboardPermission(): boolean;
|
|
38
38
|
declare function getFocusedInputValue(): string | null;
|
|
39
39
|
declare function getFocusedInputSelectedText(): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* 获取完整上下文信息(JSON 格式)
|
|
42
|
+
* 包含:应用信息、焦点元素、选中文本、DOM 信息等
|
|
43
|
+
* @returns JSON 字符串或 null
|
|
44
|
+
*/
|
|
45
|
+
declare function getContextJSON(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* 智能获取选中文本
|
|
48
|
+
* 优先用 Accessibility API,失败则用模拟 Cmd+C(支持微信等)
|
|
49
|
+
* @returns 选中文本或 null
|
|
50
|
+
*/
|
|
51
|
+
declare function getSelectedTextSmart(): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Set whether to block ALL system hotkeys involving modifier key combinations.
|
|
54
|
+
* This covers: Shift+Alt (IME switch), Ctrl+Shift (IME switch), Win+Space (IME switch),
|
|
55
|
+
* Alt release (menu activation), Win release (Start menu), etc.
|
|
56
|
+
*
|
|
57
|
+
* When enabled:
|
|
58
|
+
* - On modifier key DOWN with another modifier held: inject F13 to break system hotkey detection
|
|
59
|
+
* - On Alt release: inject F13 to prevent menu activation
|
|
60
|
+
* - On Win release: inject Shift+Win sequence to prevent Start menu
|
|
61
|
+
*
|
|
62
|
+
* Windows only - no-op on other platforms.
|
|
63
|
+
*
|
|
64
|
+
* @param block true = block all system hotkeys, false = allow normal behavior
|
|
65
|
+
*/
|
|
66
|
+
declare function setBlockSystemHotkeys(block: boolean): void;
|
|
40
67
|
|
|
41
|
-
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener };
|
|
68
|
+
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getContextJSON, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener, getSelectedTextSmart, setBlockSystemHotkeys };
|
package/dist/index.d.ts
CHANGED
|
@@ -37,5 +37,32 @@ declare function createGlobalKeyboardListener(): IGlobalKeyboardListener;
|
|
|
37
37
|
declare function checkKeyboardPermission(): boolean;
|
|
38
38
|
declare function getFocusedInputValue(): string | null;
|
|
39
39
|
declare function getFocusedInputSelectedText(): string | null;
|
|
40
|
+
/**
|
|
41
|
+
* 获取完整上下文信息(JSON 格式)
|
|
42
|
+
* 包含:应用信息、焦点元素、选中文本、DOM 信息等
|
|
43
|
+
* @returns JSON 字符串或 null
|
|
44
|
+
*/
|
|
45
|
+
declare function getContextJSON(): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* 智能获取选中文本
|
|
48
|
+
* 优先用 Accessibility API,失败则用模拟 Cmd+C(支持微信等)
|
|
49
|
+
* @returns 选中文本或 null
|
|
50
|
+
*/
|
|
51
|
+
declare function getSelectedTextSmart(): string | null;
|
|
52
|
+
/**
|
|
53
|
+
* Set whether to block ALL system hotkeys involving modifier key combinations.
|
|
54
|
+
* This covers: Shift+Alt (IME switch), Ctrl+Shift (IME switch), Win+Space (IME switch),
|
|
55
|
+
* Alt release (menu activation), Win release (Start menu), etc.
|
|
56
|
+
*
|
|
57
|
+
* When enabled:
|
|
58
|
+
* - On modifier key DOWN with another modifier held: inject F13 to break system hotkey detection
|
|
59
|
+
* - On Alt release: inject F13 to prevent menu activation
|
|
60
|
+
* - On Win release: inject Shift+Win sequence to prevent Start menu
|
|
61
|
+
*
|
|
62
|
+
* Windows only - no-op on other platforms.
|
|
63
|
+
*
|
|
64
|
+
* @param block true = block all system hotkeys, false = allow normal behavior
|
|
65
|
+
*/
|
|
66
|
+
declare function setBlockSystemHotkeys(block: boolean): void;
|
|
40
67
|
|
|
41
|
-
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener };
|
|
68
|
+
export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getContextJSON, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener, getSelectedTextSmart, setBlockSystemHotkeys };
|
package/dist/index.js
CHANGED
|
@@ -32,9 +32,12 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
checkKeyboardPermission: () => checkKeyboardPermission,
|
|
34
34
|
createGlobalKeyboardListener: () => createGlobalKeyboardListener,
|
|
35
|
+
getContextJSON: () => getContextJSON,
|
|
35
36
|
getFocusedInputSelectedText: () => getFocusedInputSelectedText,
|
|
36
37
|
getFocusedInputValue: () => getFocusedInputValue,
|
|
37
|
-
getGlobalKeyboardListener: () => getGlobalKeyboardListener
|
|
38
|
+
getGlobalKeyboardListener: () => getGlobalKeyboardListener,
|
|
39
|
+
getSelectedTextSmart: () => getSelectedTextSmart,
|
|
40
|
+
setBlockSystemHotkeys: () => setBlockSystemHotkeys
|
|
38
41
|
});
|
|
39
42
|
module.exports = __toCommonJS(index_exports);
|
|
40
43
|
var path = __toESM(require("path"));
|
|
@@ -43,6 +46,8 @@ var import_node_child_process = require("child_process");
|
|
|
43
46
|
var import_node_module = require("module");
|
|
44
47
|
var import_url = require("url");
|
|
45
48
|
var import_meta = {};
|
|
49
|
+
var IS_MACOS = process.platform === "darwin";
|
|
50
|
+
var IS_WINDOWS = process.platform === "win32";
|
|
46
51
|
var PLATFORM_PACKAGES = {
|
|
47
52
|
"darwin-arm64": "@simen-keyboard-listener/darwin-arm64",
|
|
48
53
|
"win32-x64": "@simen-keyboard-listener/win32-x64"
|
|
@@ -193,7 +198,7 @@ var NativeKeyboardListener = class _NativeKeyboardListener {
|
|
|
193
198
|
}
|
|
194
199
|
};
|
|
195
200
|
function getGlobalKeyboardListener() {
|
|
196
|
-
if (
|
|
201
|
+
if (!IS_MACOS && !IS_WINDOWS) {
|
|
197
202
|
throw new Error(`Unsupported platform for global keyboard listener: ${process.platform}`);
|
|
198
203
|
}
|
|
199
204
|
return NativeKeyboardListener.getInstance();
|
|
@@ -202,7 +207,7 @@ function createGlobalKeyboardListener() {
|
|
|
202
207
|
return getGlobalKeyboardListener();
|
|
203
208
|
}
|
|
204
209
|
function checkKeyboardPermission() {
|
|
205
|
-
if (
|
|
210
|
+
if (!IS_MACOS && !IS_WINDOWS) {
|
|
206
211
|
return false;
|
|
207
212
|
}
|
|
208
213
|
try {
|
|
@@ -214,7 +219,7 @@ function checkKeyboardPermission() {
|
|
|
214
219
|
}
|
|
215
220
|
var lastMacAccessibilitySettingsOpenTs = 0;
|
|
216
221
|
function openMacAccessibilitySettings() {
|
|
217
|
-
if (
|
|
222
|
+
if (!IS_MACOS) {
|
|
218
223
|
return;
|
|
219
224
|
}
|
|
220
225
|
const now = Date.now();
|
|
@@ -240,7 +245,7 @@ function ensureAccessibilityPermission(addon) {
|
|
|
240
245
|
return false;
|
|
241
246
|
}
|
|
242
247
|
function getFocusedInputValue() {
|
|
243
|
-
if (
|
|
248
|
+
if (!IS_MACOS) {
|
|
244
249
|
return null;
|
|
245
250
|
}
|
|
246
251
|
const addon = getNativeAddon();
|
|
@@ -254,7 +259,7 @@ function getFocusedInputValue() {
|
|
|
254
259
|
}
|
|
255
260
|
}
|
|
256
261
|
function getFocusedInputSelectedText() {
|
|
257
|
-
if (
|
|
262
|
+
if (!IS_MACOS) {
|
|
258
263
|
return null;
|
|
259
264
|
}
|
|
260
265
|
const addon = getNativeAddon();
|
|
@@ -267,11 +272,44 @@ function getFocusedInputSelectedText() {
|
|
|
267
272
|
return null;
|
|
268
273
|
}
|
|
269
274
|
}
|
|
275
|
+
function getContextJSON() {
|
|
276
|
+
if (!IS_MACOS) return null;
|
|
277
|
+
const addon = getNativeAddon();
|
|
278
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
279
|
+
try {
|
|
280
|
+
return addon.getContextJSON?.() ?? null;
|
|
281
|
+
} catch {
|
|
282
|
+
return null;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
function getSelectedTextSmart() {
|
|
286
|
+
if (!IS_MACOS) return null;
|
|
287
|
+
const addon = getNativeAddon();
|
|
288
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
289
|
+
try {
|
|
290
|
+
return addon.getSelectedTextSmart?.() ?? null;
|
|
291
|
+
} catch {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function setBlockSystemHotkeys(block) {
|
|
296
|
+
if (!IS_WINDOWS) {
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
try {
|
|
300
|
+
const addon = getNativeAddon();
|
|
301
|
+
addon.setBlockSystemHotkeys?.(block);
|
|
302
|
+
} catch {
|
|
303
|
+
}
|
|
304
|
+
}
|
|
270
305
|
// Annotate the CommonJS export names for ESM import in node:
|
|
271
306
|
0 && (module.exports = {
|
|
272
307
|
checkKeyboardPermission,
|
|
273
308
|
createGlobalKeyboardListener,
|
|
309
|
+
getContextJSON,
|
|
274
310
|
getFocusedInputSelectedText,
|
|
275
311
|
getFocusedInputValue,
|
|
276
|
-
getGlobalKeyboardListener
|
|
312
|
+
getGlobalKeyboardListener,
|
|
313
|
+
getSelectedTextSmart,
|
|
314
|
+
setBlockSystemHotkeys
|
|
277
315
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -11,6 +11,8 @@ import * as fs from "fs";
|
|
|
11
11
|
import { execFileSync } from "child_process";
|
|
12
12
|
import { createRequire } from "module";
|
|
13
13
|
import { fileURLToPath } from "url";
|
|
14
|
+
var IS_MACOS = process.platform === "darwin";
|
|
15
|
+
var IS_WINDOWS = process.platform === "win32";
|
|
14
16
|
var PLATFORM_PACKAGES = {
|
|
15
17
|
"darwin-arm64": "@simen-keyboard-listener/darwin-arm64",
|
|
16
18
|
"win32-x64": "@simen-keyboard-listener/win32-x64"
|
|
@@ -161,7 +163,7 @@ var NativeKeyboardListener = class _NativeKeyboardListener {
|
|
|
161
163
|
}
|
|
162
164
|
};
|
|
163
165
|
function getGlobalKeyboardListener() {
|
|
164
|
-
if (
|
|
166
|
+
if (!IS_MACOS && !IS_WINDOWS) {
|
|
165
167
|
throw new Error(`Unsupported platform for global keyboard listener: ${process.platform}`);
|
|
166
168
|
}
|
|
167
169
|
return NativeKeyboardListener.getInstance();
|
|
@@ -170,7 +172,7 @@ function createGlobalKeyboardListener() {
|
|
|
170
172
|
return getGlobalKeyboardListener();
|
|
171
173
|
}
|
|
172
174
|
function checkKeyboardPermission() {
|
|
173
|
-
if (
|
|
175
|
+
if (!IS_MACOS && !IS_WINDOWS) {
|
|
174
176
|
return false;
|
|
175
177
|
}
|
|
176
178
|
try {
|
|
@@ -182,7 +184,7 @@ function checkKeyboardPermission() {
|
|
|
182
184
|
}
|
|
183
185
|
var lastMacAccessibilitySettingsOpenTs = 0;
|
|
184
186
|
function openMacAccessibilitySettings() {
|
|
185
|
-
if (
|
|
187
|
+
if (!IS_MACOS) {
|
|
186
188
|
return;
|
|
187
189
|
}
|
|
188
190
|
const now = Date.now();
|
|
@@ -208,7 +210,7 @@ function ensureAccessibilityPermission(addon) {
|
|
|
208
210
|
return false;
|
|
209
211
|
}
|
|
210
212
|
function getFocusedInputValue() {
|
|
211
|
-
if (
|
|
213
|
+
if (!IS_MACOS) {
|
|
212
214
|
return null;
|
|
213
215
|
}
|
|
214
216
|
const addon = getNativeAddon();
|
|
@@ -222,7 +224,7 @@ function getFocusedInputValue() {
|
|
|
222
224
|
}
|
|
223
225
|
}
|
|
224
226
|
function getFocusedInputSelectedText() {
|
|
225
|
-
if (
|
|
227
|
+
if (!IS_MACOS) {
|
|
226
228
|
return null;
|
|
227
229
|
}
|
|
228
230
|
const addon = getNativeAddon();
|
|
@@ -235,10 +237,43 @@ function getFocusedInputSelectedText() {
|
|
|
235
237
|
return null;
|
|
236
238
|
}
|
|
237
239
|
}
|
|
240
|
+
function getContextJSON() {
|
|
241
|
+
if (!IS_MACOS) return null;
|
|
242
|
+
const addon = getNativeAddon();
|
|
243
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
244
|
+
try {
|
|
245
|
+
return addon.getContextJSON?.() ?? null;
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
function getSelectedTextSmart() {
|
|
251
|
+
if (!IS_MACOS) return null;
|
|
252
|
+
const addon = getNativeAddon();
|
|
253
|
+
if (!ensureAccessibilityPermission(addon)) return null;
|
|
254
|
+
try {
|
|
255
|
+
return addon.getSelectedTextSmart?.() ?? null;
|
|
256
|
+
} catch {
|
|
257
|
+
return null;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function setBlockSystemHotkeys(block) {
|
|
261
|
+
if (!IS_WINDOWS) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const addon = getNativeAddon();
|
|
266
|
+
addon.setBlockSystemHotkeys?.(block);
|
|
267
|
+
} catch {
|
|
268
|
+
}
|
|
269
|
+
}
|
|
238
270
|
export {
|
|
239
271
|
checkKeyboardPermission,
|
|
240
272
|
createGlobalKeyboardListener,
|
|
273
|
+
getContextJSON,
|
|
241
274
|
getFocusedInputSelectedText,
|
|
242
275
|
getFocusedInputValue,
|
|
243
|
-
getGlobalKeyboardListener
|
|
276
|
+
getGlobalKeyboardListener,
|
|
277
|
+
getSelectedTextSmart,
|
|
278
|
+
setBlockSystemHotkeys
|
|
244
279
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "simen-keyboard-listener",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "Native global keyboard listener for macOS and Windows",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,10 +16,11 @@
|
|
|
16
16
|
"dist"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build:
|
|
19
|
+
"build:swift": "cd src/native && swiftc -O -parse-as-library -c ContextHelper.swift -o ContextHelper.o",
|
|
20
|
+
"build:native": "npm run build:swift && node-gyp rebuild --directory=src/native",
|
|
20
21
|
"build:ts": "tsup src/index.ts --format cjs,esm --dts --clean",
|
|
21
22
|
"build": "npm run build:native && npm run build:ts",
|
|
22
|
-
"prebuild": "prebuildify --napi --strip --cwd src/native --out ../../prebuilds",
|
|
23
|
+
"prebuild": "npm run build:swift && prebuildify --napi --strip --cwd src/native --out ../../prebuilds",
|
|
23
24
|
"prepublishOnly": "npm run build:ts",
|
|
24
25
|
"publish:all": "node scripts/publish.js"
|
|
25
26
|
},
|
|
@@ -45,8 +46,8 @@
|
|
|
45
46
|
"node-addon-api": "^8.0.0"
|
|
46
47
|
},
|
|
47
48
|
"optionalDependencies": {
|
|
48
|
-
"@simen-keyboard-listener/darwin-arm64": "1.1.
|
|
49
|
-
"@simen-keyboard-listener/win32-x64": "1.1.
|
|
49
|
+
"@simen-keyboard-listener/darwin-arm64": "1.1.4",
|
|
50
|
+
"@simen-keyboard-listener/win32-x64": "1.1.4"
|
|
50
51
|
},
|
|
51
52
|
"devDependencies": {
|
|
52
53
|
"@types/node": "^20.0.0",
|