simen-keyboard-listener 1.1.26 → 1.1.27

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 CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2024 Simen
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.
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Simen
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 CHANGED
@@ -1,185 +1,185 @@
1
- # simen-keyboard-listener
2
-
3
- Native global keyboard listener for macOS and Windows. Captures keyboard events system-wide, including special keys like FN that cannot be detected via standard DOM events.
4
-
5
- ## Installation
6
-
7
- ```bash
8
- npm install simen-keyboard-listener
9
- ```
10
-
11
- The package uses `optionalDependencies` to automatically install the correct native binary for your platform. Supported platforms:
12
-
13
- | Package | Platform |
14
- |---------|----------|
15
- | `@simen-keyboard-listener/darwin-arm64` | macOS Apple Silicon |
16
- | `@simen-keyboard-listener/win32-x64` | Windows x64 |
17
-
18
- ### For Electron/Bundler Projects
19
-
20
- If you're using webpack, electron-builder, or other bundlers, you may need to configure them to include the native addon:
21
-
22
- **electron-builder (package.json):**
23
- ```json
24
- {
25
- "build": {
26
- "files": [
27
- "node_modules/@simen-keyboard-listener/**/*"
28
- ]
29
- }
30
- }
31
- ```
32
-
33
- **webpack (webpack.config.js):**
34
- ```javascript
35
- module.exports = {
36
- externals: {
37
- '@simen-keyboard-listener/darwin-arm64': 'commonjs @simen-keyboard-listener/darwin-arm64',
38
- '@simen-keyboard-listener/win32-x64': 'commonjs @simen-keyboard-listener/win32-x64',
39
- }
40
- };
41
- ```
42
-
43
- ## Usage
44
-
45
- ```typescript
46
- import { getGlobalKeyboardListener } from 'simen-keyboard-listener';
47
-
48
- const listener = getGlobalKeyboardListener();
49
-
50
- listener.addListener((event, isDown) => {
51
- console.log(`Key: ${event.name}, State: ${event.state}`);
52
- });
53
-
54
- // Later, to stop listening:
55
- listener.removeListener(myListener);
56
- ```
57
-
58
- ## 开发与构建
59
-
60
- ### 构建原生模块
61
-
62
- 本项目包含 C++ 和 Swift 原生代码,需要编译为平台特定的二进制文件。构建脚本会自动处理编译和文件复制。
63
-
64
- #### 一键构建(推荐)
65
-
66
- 自动检测当前平台并构建:
67
-
68
- ```bash
69
- npm run prebuild
70
- ```
71
-
72
- 此命令会:
73
- - 自动检测当前操作系统和架构
74
- - macOS:编译 Swift 辅助文件 + 构建原生模块 + 复制到 `packages/darwin-arm64/`
75
- - Windows:构建原生模块 + 复制到 `packages/win32-x64/`
76
-
77
- #### 手动指定平台构建
78
-
79
- **Windows 平台:**
80
- ```bash
81
- npm run prebuild:win
82
- ```
83
-
84
- **macOS 平台:**
85
- ```bash
86
- npm run prebuild:mac
87
- ```
88
-
89
- #### 仅复制已构建的文件
90
-
91
- 如果已经构建完成,只需要复制文件到 packages 目录:
92
-
93
- ```bash
94
- npm run copy-native win32-x64 # Windows
95
- npm run copy-native darwin-arm64 # macOS
96
- ```
97
-
98
- #### 完整构建流程
99
-
100
- 如果需要构建 TypeScript 代码和原生模块:
101
-
102
- ```bash
103
- npm run build
104
- ```
105
-
106
- 这会执行:
107
- 1. 编译 Swift 文件(macOS)
108
- 2. 构建原生模块(node-gyp)
109
- 3. 编译 TypeScript 代码
110
-
111
- ### 发布流程
112
-
113
- 发布所有平台包到 npm:
114
-
115
- ```bash
116
- npm run publish:all
117
- ```
118
-
119
- 发布脚本会:
120
- 1. 同步所有平台包的版本号
121
- 2. 检查 `.node` 文件是否存在
122
- 3. 依次发布各平台包
123
- 4. 最后发布主包
124
-
125
- **注意:** 发布前需要确保所有平台的 `.node` 文件都已构建并复制到对应的 `packages/` 目录。
126
-
127
- ## API
128
-
129
- ### `getGlobalKeyboardListener(): IGlobalKeyboardListener`
130
-
131
- Returns the singleton keyboard listener instance.
132
-
133
- ### `IGlobalKeyboardListener`
134
-
135
- - `addListener(listener: IGlobalKeyListener): void` - Add a key event listener
136
- - `removeListener(listener: IGlobalKeyListener): void` - Remove a listener
137
- - `kill(): void` - Stop the listener (only when no listeners remain)
138
-
139
- ### `IGlobalKeyEvent`
140
-
141
- ```typescript
142
- interface IGlobalKeyEvent {
143
- readonly name: string; // e.g. "FN", "LEFT SHIFT", "A", "ESCAPE"
144
- readonly state: 'DOWN' | 'UP';
145
- }
146
- ```
147
-
148
- ### Context APIs (macOS & Windows)
149
-
150
- 这些 API 在 macOS 和 Windows 上都可用:
151
-
152
- - `getSelectedTextSmart(): string | null` - 获取选中文本(必要时模拟 Cmd+C / Ctrl+C)
153
- - `getContextJSON(): string | null` - 获取完整上下文(JSON)
154
- - `getFrontmostAppInfo(): IAppInfo | null` - 获取前台应用信息
155
- - `getFocusedElementInfo(): IElementInfo | null` - 获取焦点元素信息
156
- - `getFocusedTextInfo(): ITextInfo | null` - 获取文本信息(选中/输入框等)
157
- - `getFocusedDOMInfo(): IDOMInfo | null` - 获取浏览器 DOM 信息(仅浏览器应用)
158
-
159
- **平台差异:**
160
- - macOS: 使用 Accessibility API,需要辅助功能权限
161
- - Windows: 使用 UI Automation API,无需特殊权限
162
-
163
- ## Supported Keys
164
-
165
- - **Modifiers**: FN (macOS), SHIFT, CTRL, ALT, META (Cmd/Win)
166
- - **Letters**: A-Z
167
- - **Numbers**: 0-9
168
- - **Function keys**: F1-F12 (Windows)
169
- - **Special**: ESCAPE, SPACE, RETURN, TAB, BACKSPACE, DELETE
170
- - **Arrows**: UP, DOWN, LEFT, RIGHT
171
-
172
- ## Platform Support
173
-
174
- - macOS ARM64 (Apple Silicon)
175
- - Windows x64
176
-
177
- ## Requirements
178
-
179
- - Node.js >= 18.0.0
180
- - macOS: Accessibility permission required
181
- - Windows: No special permissions needed
182
-
183
- ## License
184
-
185
- MIT
1
+ # simen-keyboard-listener
2
+
3
+ Native global keyboard listener for macOS and Windows. Captures keyboard events system-wide, including special keys like FN that cannot be detected via standard DOM events.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install simen-keyboard-listener
9
+ ```
10
+
11
+ The package uses `optionalDependencies` to automatically install the correct native binary for your platform. Supported platforms:
12
+
13
+ | Package | Platform |
14
+ |---------|----------|
15
+ | `@simen-keyboard-listener/darwin-arm64` | macOS Apple Silicon |
16
+ | `@simen-keyboard-listener/win32-x64` | Windows x64 |
17
+
18
+ ### For Electron/Bundler Projects
19
+
20
+ If you're using webpack, electron-builder, or other bundlers, you may need to configure them to include the native addon:
21
+
22
+ **electron-builder (package.json):**
23
+ ```json
24
+ {
25
+ "build": {
26
+ "files": [
27
+ "node_modules/@simen-keyboard-listener/**/*"
28
+ ]
29
+ }
30
+ }
31
+ ```
32
+
33
+ **webpack (webpack.config.js):**
34
+ ```javascript
35
+ module.exports = {
36
+ externals: {
37
+ '@simen-keyboard-listener/darwin-arm64': 'commonjs @simen-keyboard-listener/darwin-arm64',
38
+ '@simen-keyboard-listener/win32-x64': 'commonjs @simen-keyboard-listener/win32-x64',
39
+ }
40
+ };
41
+ ```
42
+
43
+ ## Usage
44
+
45
+ ```typescript
46
+ import { getGlobalKeyboardListener } from 'simen-keyboard-listener';
47
+
48
+ const listener = getGlobalKeyboardListener();
49
+
50
+ listener.addListener((event, isDown) => {
51
+ console.log(`Key: ${event.name}, State: ${event.state}`);
52
+ });
53
+
54
+ // Later, to stop listening:
55
+ listener.removeListener(myListener);
56
+ ```
57
+
58
+ ## 开发与构建
59
+
60
+ ### 构建原生模块
61
+
62
+ 本项目包含 C++ 和 Swift 原生代码,需要编译为平台特定的二进制文件。构建脚本会自动处理编译和文件复制。
63
+
64
+ #### 一键构建(推荐)
65
+
66
+ 自动检测当前平台并构建:
67
+
68
+ ```bash
69
+ npm run prebuild
70
+ ```
71
+
72
+ 此命令会:
73
+ - 自动检测当前操作系统和架构
74
+ - macOS:编译 Swift 辅助文件 + 构建原生模块 + 复制到 `packages/darwin-arm64/`
75
+ - Windows:构建原生模块 + 复制到 `packages/win32-x64/`
76
+
77
+ #### 手动指定平台构建
78
+
79
+ **Windows 平台:**
80
+ ```bash
81
+ npm run prebuild:win
82
+ ```
83
+
84
+ **macOS 平台:**
85
+ ```bash
86
+ npm run prebuild:mac
87
+ ```
88
+
89
+ #### 仅复制已构建的文件
90
+
91
+ 如果已经构建完成,只需要复制文件到 packages 目录:
92
+
93
+ ```bash
94
+ npm run copy-native win32-x64 # Windows
95
+ npm run copy-native darwin-arm64 # macOS
96
+ ```
97
+
98
+ #### 完整构建流程
99
+
100
+ 如果需要构建 TypeScript 代码和原生模块:
101
+
102
+ ```bash
103
+ npm run build
104
+ ```
105
+
106
+ 这会执行:
107
+ 1. 编译 Swift 文件(macOS)
108
+ 2. 构建原生模块(node-gyp)
109
+ 3. 编译 TypeScript 代码
110
+
111
+ ### 发布流程
112
+
113
+ 发布所有平台包到 npm:
114
+
115
+ ```bash
116
+ npm run publish:all
117
+ ```
118
+
119
+ 发布脚本会:
120
+ 1. 同步所有平台包的版本号
121
+ 2. 检查 `.node` 文件是否存在
122
+ 3. 依次发布各平台包
123
+ 4. 最后发布主包
124
+
125
+ **注意:** 发布前需要确保所有平台的 `.node` 文件都已构建并复制到对应的 `packages/` 目录。
126
+
127
+ ## API
128
+
129
+ ### `getGlobalKeyboardListener(): IGlobalKeyboardListener`
130
+
131
+ Returns the singleton keyboard listener instance.
132
+
133
+ ### `IGlobalKeyboardListener`
134
+
135
+ - `addListener(listener: IGlobalKeyListener): void` - Add a key event listener
136
+ - `removeListener(listener: IGlobalKeyListener): void` - Remove a listener
137
+ - `kill(): void` - Stop the listener (only when no listeners remain)
138
+
139
+ ### `IGlobalKeyEvent`
140
+
141
+ ```typescript
142
+ interface IGlobalKeyEvent {
143
+ readonly name: string; // e.g. "FN", "LEFT SHIFT", "A", "ESCAPE"
144
+ readonly state: 'DOWN' | 'UP';
145
+ }
146
+ ```
147
+
148
+ ### Context APIs (macOS & Windows)
149
+
150
+ 这些 API 在 macOS 和 Windows 上都可用:
151
+
152
+ - `getSelectedTextSmart(): string | null` - 获取选中文本(必要时模拟 Cmd+C / Ctrl+C)
153
+ - `getContextJSON(): string | null` - 获取完整上下文(JSON)
154
+ - `getFrontmostAppInfo(): IAppInfo | null` - 获取前台应用信息
155
+ - `getFocusedElementInfo(): IElementInfo | null` - 获取焦点元素信息
156
+ - `getFocusedTextInfo(): ITextInfo | null` - 获取文本信息(选中/输入框等)
157
+ - `getFocusedDOMInfo(): IDOMInfo | null` - 获取浏览器 DOM 信息(仅浏览器应用)
158
+
159
+ **平台差异:**
160
+ - macOS: 使用 Accessibility API,需要辅助功能权限
161
+ - Windows: 使用 UI Automation API,无需特殊权限
162
+
163
+ ## Supported Keys
164
+
165
+ - **Modifiers**: FN (macOS), SHIFT, CTRL, ALT, META (Cmd/Win)
166
+ - **Letters**: A-Z
167
+ - **Numbers**: 0-9
168
+ - **Function keys**: F1-F12 (Windows)
169
+ - **Special**: ESCAPE, SPACE, RETURN, TAB, BACKSPACE, DELETE
170
+ - **Arrows**: UP, DOWN, LEFT, RIGHT
171
+
172
+ ## Platform Support
173
+
174
+ - macOS ARM64 (Apple Silicon)
175
+ - Windows x64
176
+
177
+ ## Requirements
178
+
179
+ - Node.js >= 18.0.0
180
+ - macOS: Accessibility permission required
181
+ - Windows: No special permissions needed
182
+
183
+ ## License
184
+
185
+ MIT
package/dist/index.d.mts CHANGED
@@ -916,13 +916,25 @@ declare function getGlobalKeyboardListener(): IGlobalKeyboardListener;
916
916
  declare function createGlobalKeyboardListener(): IGlobalKeyboardListener;
917
917
  /**
918
918
  * Check if the app has permission to listen to global keyboard events.
919
- * - On macOS: checks accessibility permission (System Preferences > Security & Privacy > Accessibility)
919
+ * - On macOS: uses multi-layer detection CGPreflightListenEventAccess
920
+ * (Input Monitoring) OR AXIsProcessTrusted (Accessibility). This ensures
921
+ * correct behavior on macOS 14 (where AXIsProcessTrusted may be unreliable
922
+ * for signed apps) and macOS 15/26 (where only Accessibility is needed).
920
923
  * - On Windows: always returns true (no special permission needed)
921
924
  * - On other platforms: returns false
922
925
  *
923
926
  * Call this before starting the listener to provide better UX when permission is missing.
924
927
  */
925
928
  declare function checkKeyboardPermission(): boolean;
929
+ /**
930
+ * Request Input Monitoring permission on macOS.
931
+ * Calls CGRequestListenEventAccess which triggers the system permission prompt
932
+ * on first call. This is separate from Accessibility permission.
933
+ * - On macOS: returns true if already granted, false if user needs to grant it
934
+ * - On Windows: always returns true
935
+ * - On other platforms: returns false
936
+ */
937
+ declare function requestKeyboardPermission(): boolean;
926
938
  /**
927
939
  * Check if the currently focused element is editable
928
940
  * @returns true if focused element is editable, false otherwise
@@ -994,4 +1006,4 @@ declare function setBlockSystemHotkeys(block: boolean): void;
994
1006
  */
995
1007
  declare function setBlockedShortcuts(shortcuts: string[]): void;
996
1008
 
997
- export { type IAgentContext$1 as IAgentContext, type IAgentContextOptions$1 as IAgentContextOptions, type IClipboardContent$1 as IClipboardContent, type IDesktopItem$1 as IDesktopItem, type IExecuteOptions$1 as IExecuteOptions, type IExecuteResult$1 as IExecuteResult, type IFileContent$1 as IFileContent, type IFileMetadata$1 as IFileMetadata, type IFinderContext, type IFinderItem, type IFinderSelection, type IFinderWindow, type IFinderWindowInfo, type IFinderWindowItem, type IFrontmostApp$1 as IFrontmostApp, type IFrontmostInfo, type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPageContextInfo, type IPermissionLostListener, type IReadFileOptions$1 as IReadFileOptions, type IRecentFile$1 as IRecentFile, type IRunningApp$1 as IRunningApp, type ISelectedItem$1 as ISelectedItem, type ISystemContext$1 as ISystemContext, checkKeyboardPermission, createGlobalKeyboardListener, escapeForAppleScript, executeAndParse$1 as executeAndParse, executeAppleScript, executeAppleScriptLines, executeMultilineAndParse$1 as executeMultilineAndParse, getAgentContext$1 as getAgentContext, getClipboardContent$1 as getClipboardContent, getClipboardText$1 as getClipboardText, getDesktopItems, getDesktopPath, getFileMetadata, getFilesMetadata, getFinderContext, getFinderCurrentFolder, getFinderSelection, getFinderWindows, getFocusedValue, getFrontmostApp$1 as getFrontmostApp, getFrontmostFromRunning, getFrontmostInfo, getGlobalKeyboardListener, getPageContext, getRecentDocuments, getRecentFiles, getRunningApps, getSelectedTextSmart, getSystemContext$1 as getSystemContext, isAppRunning, isEditable, isOsascriptAvailable, index as powershell, readFileContent, readMultipleFiles, setBlockSystemHotkeys, setBlockedShortcuts };
1009
+ export { type IAgentContext$1 as IAgentContext, type IAgentContextOptions$1 as IAgentContextOptions, type IClipboardContent$1 as IClipboardContent, type IDesktopItem$1 as IDesktopItem, type IExecuteOptions$1 as IExecuteOptions, type IExecuteResult$1 as IExecuteResult, type IFileContent$1 as IFileContent, type IFileMetadata$1 as IFileMetadata, type IFinderContext, type IFinderItem, type IFinderSelection, type IFinderWindow, type IFinderWindowInfo, type IFinderWindowItem, type IFrontmostApp$1 as IFrontmostApp, type IFrontmostInfo, type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPageContextInfo, type IPermissionLostListener, type IReadFileOptions$1 as IReadFileOptions, type IRecentFile$1 as IRecentFile, type IRunningApp$1 as IRunningApp, type ISelectedItem$1 as ISelectedItem, type ISystemContext$1 as ISystemContext, checkKeyboardPermission, createGlobalKeyboardListener, escapeForAppleScript, executeAndParse$1 as executeAndParse, executeAppleScript, executeAppleScriptLines, executeMultilineAndParse$1 as executeMultilineAndParse, getAgentContext$1 as getAgentContext, getClipboardContent$1 as getClipboardContent, getClipboardText$1 as getClipboardText, getDesktopItems, getDesktopPath, getFileMetadata, getFilesMetadata, getFinderContext, getFinderCurrentFolder, getFinderSelection, getFinderWindows, getFocusedValue, getFrontmostApp$1 as getFrontmostApp, getFrontmostFromRunning, getFrontmostInfo, getGlobalKeyboardListener, getPageContext, getRecentDocuments, getRecentFiles, getRunningApps, getSelectedTextSmart, getSystemContext$1 as getSystemContext, isAppRunning, isEditable, isOsascriptAvailable, index as powershell, readFileContent, readMultipleFiles, requestKeyboardPermission, setBlockSystemHotkeys, setBlockedShortcuts };
package/dist/index.d.ts CHANGED
@@ -916,13 +916,25 @@ declare function getGlobalKeyboardListener(): IGlobalKeyboardListener;
916
916
  declare function createGlobalKeyboardListener(): IGlobalKeyboardListener;
917
917
  /**
918
918
  * Check if the app has permission to listen to global keyboard events.
919
- * - On macOS: checks accessibility permission (System Preferences > Security & Privacy > Accessibility)
919
+ * - On macOS: uses multi-layer detection CGPreflightListenEventAccess
920
+ * (Input Monitoring) OR AXIsProcessTrusted (Accessibility). This ensures
921
+ * correct behavior on macOS 14 (where AXIsProcessTrusted may be unreliable
922
+ * for signed apps) and macOS 15/26 (where only Accessibility is needed).
920
923
  * - On Windows: always returns true (no special permission needed)
921
924
  * - On other platforms: returns false
922
925
  *
923
926
  * Call this before starting the listener to provide better UX when permission is missing.
924
927
  */
925
928
  declare function checkKeyboardPermission(): boolean;
929
+ /**
930
+ * Request Input Monitoring permission on macOS.
931
+ * Calls CGRequestListenEventAccess which triggers the system permission prompt
932
+ * on first call. This is separate from Accessibility permission.
933
+ * - On macOS: returns true if already granted, false if user needs to grant it
934
+ * - On Windows: always returns true
935
+ * - On other platforms: returns false
936
+ */
937
+ declare function requestKeyboardPermission(): boolean;
926
938
  /**
927
939
  * Check if the currently focused element is editable
928
940
  * @returns true if focused element is editable, false otherwise
@@ -994,4 +1006,4 @@ declare function setBlockSystemHotkeys(block: boolean): void;
994
1006
  */
995
1007
  declare function setBlockedShortcuts(shortcuts: string[]): void;
996
1008
 
997
- export { type IAgentContext$1 as IAgentContext, type IAgentContextOptions$1 as IAgentContextOptions, type IClipboardContent$1 as IClipboardContent, type IDesktopItem$1 as IDesktopItem, type IExecuteOptions$1 as IExecuteOptions, type IExecuteResult$1 as IExecuteResult, type IFileContent$1 as IFileContent, type IFileMetadata$1 as IFileMetadata, type IFinderContext, type IFinderItem, type IFinderSelection, type IFinderWindow, type IFinderWindowInfo, type IFinderWindowItem, type IFrontmostApp$1 as IFrontmostApp, type IFrontmostInfo, type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPageContextInfo, type IPermissionLostListener, type IReadFileOptions$1 as IReadFileOptions, type IRecentFile$1 as IRecentFile, type IRunningApp$1 as IRunningApp, type ISelectedItem$1 as ISelectedItem, type ISystemContext$1 as ISystemContext, checkKeyboardPermission, createGlobalKeyboardListener, escapeForAppleScript, executeAndParse$1 as executeAndParse, executeAppleScript, executeAppleScriptLines, executeMultilineAndParse$1 as executeMultilineAndParse, getAgentContext$1 as getAgentContext, getClipboardContent$1 as getClipboardContent, getClipboardText$1 as getClipboardText, getDesktopItems, getDesktopPath, getFileMetadata, getFilesMetadata, getFinderContext, getFinderCurrentFolder, getFinderSelection, getFinderWindows, getFocusedValue, getFrontmostApp$1 as getFrontmostApp, getFrontmostFromRunning, getFrontmostInfo, getGlobalKeyboardListener, getPageContext, getRecentDocuments, getRecentFiles, getRunningApps, getSelectedTextSmart, getSystemContext$1 as getSystemContext, isAppRunning, isEditable, isOsascriptAvailable, index as powershell, readFileContent, readMultipleFiles, setBlockSystemHotkeys, setBlockedShortcuts };
1009
+ export { type IAgentContext$1 as IAgentContext, type IAgentContextOptions$1 as IAgentContextOptions, type IClipboardContent$1 as IClipboardContent, type IDesktopItem$1 as IDesktopItem, type IExecuteOptions$1 as IExecuteOptions, type IExecuteResult$1 as IExecuteResult, type IFileContent$1 as IFileContent, type IFileMetadata$1 as IFileMetadata, type IFinderContext, type IFinderItem, type IFinderSelection, type IFinderWindow, type IFinderWindowInfo, type IFinderWindowItem, type IFrontmostApp$1 as IFrontmostApp, type IFrontmostInfo, type IGlobalKeyDownMap, type IGlobalKeyEvent, type IGlobalKeyListener, type IGlobalKeyState, type IGlobalKeyboardListener, type IPageContextInfo, type IPermissionLostListener, type IReadFileOptions$1 as IReadFileOptions, type IRecentFile$1 as IRecentFile, type IRunningApp$1 as IRunningApp, type ISelectedItem$1 as ISelectedItem, type ISystemContext$1 as ISystemContext, checkKeyboardPermission, createGlobalKeyboardListener, escapeForAppleScript, executeAndParse$1 as executeAndParse, executeAppleScript, executeAppleScriptLines, executeMultilineAndParse$1 as executeMultilineAndParse, getAgentContext$1 as getAgentContext, getClipboardContent$1 as getClipboardContent, getClipboardText$1 as getClipboardText, getDesktopItems, getDesktopPath, getFileMetadata, getFilesMetadata, getFinderContext, getFinderCurrentFolder, getFinderSelection, getFinderWindows, getFocusedValue, getFrontmostApp$1 as getFrontmostApp, getFrontmostFromRunning, getFrontmostInfo, getGlobalKeyboardListener, getPageContext, getRecentDocuments, getRecentFiles, getRunningApps, getSelectedTextSmart, getSystemContext$1 as getSystemContext, isAppRunning, isEditable, isOsascriptAvailable, index as powershell, readFileContent, readMultipleFiles, requestKeyboardPermission, setBlockSystemHotkeys, setBlockedShortcuts };
package/dist/index.js CHANGED
@@ -65,6 +65,7 @@ __export(index_exports, {
65
65
  powershell: () => powershell_exports,
66
66
  readFileContent: () => readFileContent,
67
67
  readMultipleFiles: () => readMultipleFiles,
68
+ requestKeyboardPermission: () => requestKeyboardPermission,
68
69
  setBlockSystemHotkeys: () => setBlockSystemHotkeys,
69
70
  setBlockedShortcuts: () => setBlockedShortcuts
70
71
  });
@@ -2470,6 +2471,17 @@ function checkKeyboardPermission() {
2470
2471
  return false;
2471
2472
  }
2472
2473
  }
2474
+ function requestKeyboardPermission() {
2475
+ if (!IS_MACOS2 && !IS_WINDOWS2) {
2476
+ return false;
2477
+ }
2478
+ try {
2479
+ const addon = getNativeAddon();
2480
+ return addon.requestListenPermission?.() ?? false;
2481
+ } catch {
2482
+ return false;
2483
+ }
2484
+ }
2473
2485
  var lastMacAccessibilitySettingsOpenTs = 0;
2474
2486
  function openMacAccessibilitySettings() {
2475
2487
  if (!IS_MACOS2) {
@@ -2604,6 +2616,7 @@ function setBlockedShortcuts(shortcuts) {
2604
2616
  powershell,
2605
2617
  readFileContent,
2606
2618
  readMultipleFiles,
2619
+ requestKeyboardPermission,
2607
2620
  setBlockSystemHotkeys,
2608
2621
  setBlockedShortcuts
2609
2622
  });
package/dist/index.mjs CHANGED
@@ -2411,6 +2411,17 @@ function checkKeyboardPermission() {
2411
2411
  return false;
2412
2412
  }
2413
2413
  }
2414
+ function requestKeyboardPermission() {
2415
+ if (!IS_MACOS2 && !IS_WINDOWS2) {
2416
+ return false;
2417
+ }
2418
+ try {
2419
+ const addon = getNativeAddon();
2420
+ return addon.requestListenPermission?.() ?? false;
2421
+ } catch {
2422
+ return false;
2423
+ }
2424
+ }
2414
2425
  var lastMacAccessibilitySettingsOpenTs = 0;
2415
2426
  function openMacAccessibilitySettings() {
2416
2427
  if (!IS_MACOS2) {
@@ -2544,6 +2555,7 @@ export {
2544
2555
  powershell_exports as powershell,
2545
2556
  readFileContent,
2546
2557
  readMultipleFiles,
2558
+ requestKeyboardPermission,
2547
2559
  setBlockSystemHotkeys,
2548
2560
  setBlockedShortcuts
2549
2561
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simen-keyboard-listener",
3
- "version": "1.1.26",
3
+ "version": "1.1.27",
4
4
  "description": "Native global keyboard listener for macOS and Windows",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -50,8 +50,8 @@
50
50
  "node-addon-api": "^8.0.0"
51
51
  },
52
52
  "optionalDependencies": {
53
- "@simen-keyboard-listener/darwin-arm64": "1.1.26",
54
- "@simen-keyboard-listener/win32-x64": "1.1.26"
53
+ "@simen-keyboard-listener/darwin-arm64": "1.1.27",
54
+ "@simen-keyboard-listener/win32-x64": "1.1.27"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/node": "^20.0.0",