simen-keyboard-listener 1.1.3 → 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 CHANGED
@@ -49,5 +49,20 @@ declare function getContextJSON(): string | null;
49
49
  * @returns 选中文本或 null
50
50
  */
51
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;
52
67
 
53
- export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getContextJSON, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener, getSelectedTextSmart };
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
@@ -49,5 +49,20 @@ declare function getContextJSON(): string | null;
49
49
  * @returns 选中文本或 null
50
50
  */
51
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;
52
67
 
53
- export { type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPermissionLostListener, checkKeyboardPermission, createGlobalKeyboardListener, getContextJSON, getFocusedInputSelectedText, getFocusedInputValue, getGlobalKeyboardListener, getSelectedTextSmart };
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
@@ -36,7 +36,8 @@ __export(index_exports, {
36
36
  getFocusedInputSelectedText: () => getFocusedInputSelectedText,
37
37
  getFocusedInputValue: () => getFocusedInputValue,
38
38
  getGlobalKeyboardListener: () => getGlobalKeyboardListener,
39
- getSelectedTextSmart: () => getSelectedTextSmart
39
+ getSelectedTextSmart: () => getSelectedTextSmart,
40
+ setBlockSystemHotkeys: () => setBlockSystemHotkeys
40
41
  });
41
42
  module.exports = __toCommonJS(index_exports);
42
43
  var path = __toESM(require("path"));
@@ -45,6 +46,8 @@ var import_node_child_process = require("child_process");
45
46
  var import_node_module = require("module");
46
47
  var import_url = require("url");
47
48
  var import_meta = {};
49
+ var IS_MACOS = process.platform === "darwin";
50
+ var IS_WINDOWS = process.platform === "win32";
48
51
  var PLATFORM_PACKAGES = {
49
52
  "darwin-arm64": "@simen-keyboard-listener/darwin-arm64",
50
53
  "win32-x64": "@simen-keyboard-listener/win32-x64"
@@ -195,7 +198,7 @@ var NativeKeyboardListener = class _NativeKeyboardListener {
195
198
  }
196
199
  };
197
200
  function getGlobalKeyboardListener() {
198
- if (process.platform !== "darwin" && process.platform !== "win32") {
201
+ if (!IS_MACOS && !IS_WINDOWS) {
199
202
  throw new Error(`Unsupported platform for global keyboard listener: ${process.platform}`);
200
203
  }
201
204
  return NativeKeyboardListener.getInstance();
@@ -204,7 +207,7 @@ function createGlobalKeyboardListener() {
204
207
  return getGlobalKeyboardListener();
205
208
  }
206
209
  function checkKeyboardPermission() {
207
- if (process.platform !== "darwin" && process.platform !== "win32") {
210
+ if (!IS_MACOS && !IS_WINDOWS) {
208
211
  return false;
209
212
  }
210
213
  try {
@@ -216,7 +219,7 @@ function checkKeyboardPermission() {
216
219
  }
217
220
  var lastMacAccessibilitySettingsOpenTs = 0;
218
221
  function openMacAccessibilitySettings() {
219
- if (process.platform !== "darwin") {
222
+ if (!IS_MACOS) {
220
223
  return;
221
224
  }
222
225
  const now = Date.now();
@@ -242,7 +245,7 @@ function ensureAccessibilityPermission(addon) {
242
245
  return false;
243
246
  }
244
247
  function getFocusedInputValue() {
245
- if (process.platform !== "darwin") {
248
+ if (!IS_MACOS) {
246
249
  return null;
247
250
  }
248
251
  const addon = getNativeAddon();
@@ -256,7 +259,7 @@ function getFocusedInputValue() {
256
259
  }
257
260
  }
258
261
  function getFocusedInputSelectedText() {
259
- if (process.platform !== "darwin") {
262
+ if (!IS_MACOS) {
260
263
  return null;
261
264
  }
262
265
  const addon = getNativeAddon();
@@ -270,7 +273,7 @@ function getFocusedInputSelectedText() {
270
273
  }
271
274
  }
272
275
  function getContextJSON() {
273
- if (process.platform !== "darwin") return null;
276
+ if (!IS_MACOS) return null;
274
277
  const addon = getNativeAddon();
275
278
  if (!ensureAccessibilityPermission(addon)) return null;
276
279
  try {
@@ -280,7 +283,7 @@ function getContextJSON() {
280
283
  }
281
284
  }
282
285
  function getSelectedTextSmart() {
283
- if (process.platform !== "darwin") return null;
286
+ if (!IS_MACOS) return null;
284
287
  const addon = getNativeAddon();
285
288
  if (!ensureAccessibilityPermission(addon)) return null;
286
289
  try {
@@ -289,6 +292,16 @@ function getSelectedTextSmart() {
289
292
  return null;
290
293
  }
291
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
+ }
292
305
  // Annotate the CommonJS export names for ESM import in node:
293
306
  0 && (module.exports = {
294
307
  checkKeyboardPermission,
@@ -297,5 +310,6 @@ function getSelectedTextSmart() {
297
310
  getFocusedInputSelectedText,
298
311
  getFocusedInputValue,
299
312
  getGlobalKeyboardListener,
300
- getSelectedTextSmart
313
+ getSelectedTextSmart,
314
+ setBlockSystemHotkeys
301
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 (process.platform !== "darwin" && process.platform !== "win32") {
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 (process.platform !== "darwin" && process.platform !== "win32") {
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 (process.platform !== "darwin") {
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 (process.platform !== "darwin") {
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 (process.platform !== "darwin") {
227
+ if (!IS_MACOS) {
226
228
  return null;
227
229
  }
228
230
  const addon = getNativeAddon();
@@ -236,7 +238,7 @@ function getFocusedInputSelectedText() {
236
238
  }
237
239
  }
238
240
  function getContextJSON() {
239
- if (process.platform !== "darwin") return null;
241
+ if (!IS_MACOS) return null;
240
242
  const addon = getNativeAddon();
241
243
  if (!ensureAccessibilityPermission(addon)) return null;
242
244
  try {
@@ -246,7 +248,7 @@ function getContextJSON() {
246
248
  }
247
249
  }
248
250
  function getSelectedTextSmart() {
249
- if (process.platform !== "darwin") return null;
251
+ if (!IS_MACOS) return null;
250
252
  const addon = getNativeAddon();
251
253
  if (!ensureAccessibilityPermission(addon)) return null;
252
254
  try {
@@ -255,6 +257,16 @@ function getSelectedTextSmart() {
255
257
  return null;
256
258
  }
257
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
+ }
258
270
  export {
259
271
  checkKeyboardPermission,
260
272
  createGlobalKeyboardListener,
@@ -262,5 +274,6 @@ export {
262
274
  getFocusedInputSelectedText,
263
275
  getFocusedInputValue,
264
276
  getGlobalKeyboardListener,
265
- getSelectedTextSmart
277
+ getSelectedTextSmart,
278
+ setBlockSystemHotkeys
266
279
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simen-keyboard-listener",
3
- "version": "1.1.3",
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",
@@ -46,8 +46,8 @@
46
46
  "node-addon-api": "^8.0.0"
47
47
  },
48
48
  "optionalDependencies": {
49
- "@simen-keyboard-listener/darwin-arm64": "1.1.3",
50
- "@simen-keyboard-listener/win32-x64": "1.1.3"
49
+ "@simen-keyboard-listener/darwin-arm64": "1.1.4",
50
+ "@simen-keyboard-listener/win32-x64": "1.1.4"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^20.0.0",