simen-keyboard-listener 1.1.15 → 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.
Files changed (3) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +170 -170
  3. package/package.json +3 -3
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,170 +1,170 @@
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
- ## Supported Keys
149
-
150
- - **Modifiers**: FN (macOS), SHIFT, CTRL, ALT, META (Cmd/Win)
151
- - **Letters**: A-Z
152
- - **Numbers**: 0-9
153
- - **Function keys**: F1-F12 (Windows)
154
- - **Special**: ESCAPE, SPACE, RETURN, TAB, BACKSPACE, DELETE
155
- - **Arrows**: UP, DOWN, LEFT, RIGHT
156
-
157
- ## Platform Support
158
-
159
- - macOS ARM64 (Apple Silicon)
160
- - Windows x64
161
-
162
- ## Requirements
163
-
164
- - Node.js >= 18.0.0
165
- - macOS: Accessibility permission required
166
- - Windows: No special permissions needed
167
-
168
- ## License
169
-
170
- 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
+ ## Supported Keys
149
+
150
+ - **Modifiers**: FN (macOS), SHIFT, CTRL, ALT, META (Cmd/Win)
151
+ - **Letters**: A-Z
152
+ - **Numbers**: 0-9
153
+ - **Function keys**: F1-F12 (Windows)
154
+ - **Special**: ESCAPE, SPACE, RETURN, TAB, BACKSPACE, DELETE
155
+ - **Arrows**: UP, DOWN, LEFT, RIGHT
156
+
157
+ ## Platform Support
158
+
159
+ - macOS ARM64 (Apple Silicon)
160
+ - Windows x64
161
+
162
+ ## Requirements
163
+
164
+ - Node.js >= 18.0.0
165
+ - macOS: Accessibility permission required
166
+ - Windows: No special permissions needed
167
+
168
+ ## License
169
+
170
+ MIT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "simen-keyboard-listener",
3
- "version": "1.1.15",
3
+ "version": "1.1.17",
4
4
  "description": "Native global keyboard listener for macOS and Windows",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -49,8 +49,8 @@
49
49
  "node-addon-api": "^8.0.0"
50
50
  },
51
51
  "optionalDependencies": {
52
- "@simen-keyboard-listener/darwin-arm64": "1.1.15",
53
- "@simen-keyboard-listener/win32-x64": "1.1.15"
52
+ "@simen-keyboard-listener/darwin-arm64": "1.1.17",
53
+ "@simen-keyboard-listener/win32-x64": "1.1.17"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/node": "^20.0.0",