@mukea/uiohook-napi 1.5.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.
Files changed (38) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +77 -0
  3. package/binding.gyp +85 -0
  4. package/dist/index.d.ts +194 -0
  5. package/dist/index.js +206 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/prebuild-test-noop.d.ts +0 -0
  8. package/dist/prebuild-test-noop.js +3 -0
  9. package/dist/prebuild-test-noop.js.map +1 -0
  10. package/libuiohook/include/uiohook.h +457 -0
  11. package/libuiohook/src/darwin/input_helper.c +535 -0
  12. package/libuiohook/src/darwin/input_helper.h +203 -0
  13. package/libuiohook/src/darwin/input_hook.c +1436 -0
  14. package/libuiohook/src/darwin/post_event.c +303 -0
  15. package/libuiohook/src/darwin/system_properties.c +479 -0
  16. package/libuiohook/src/logger.c +40 -0
  17. package/libuiohook/src/logger.h +32 -0
  18. package/libuiohook/src/windows/input_helper.c +913 -0
  19. package/libuiohook/src/windows/input_helper.h +146 -0
  20. package/libuiohook/src/windows/input_hook.c +722 -0
  21. package/libuiohook/src/windows/post_event.c +248 -0
  22. package/libuiohook/src/windows/system_properties.c +231 -0
  23. package/libuiohook/src/x11/input_helper.c +1846 -0
  24. package/libuiohook/src/x11/input_helper.h +108 -0
  25. package/libuiohook/src/x11/input_hook.c +1116 -0
  26. package/libuiohook/src/x11/post_event.c +427 -0
  27. package/libuiohook/src/x11/system_properties.c +494 -0
  28. package/package.json +60 -0
  29. package/prebuilds/darwin/darwin-arm64/@mukea+uiohook-napi.node +0 -0
  30. package/prebuilds/darwin/darwin-x64/@mukea+uiohook-napi.node +0 -0
  31. package/prebuilds/linux/linux-arm64/@mukea+uiohook-napi.node +0 -0
  32. package/prebuilds/linux/linux-x64/@mukea+uiohook-napi.node +0 -0
  33. package/prebuilds/windows/win32-x64/@mukea+uiohook-napi.node +0 -0
  34. package/src/lib/addon.c +337 -0
  35. package/src/lib/napi_helpers.c +51 -0
  36. package/src/lib/napi_helpers.h +53 -0
  37. package/src/lib/uiohook_worker.c +200 -0
  38. package/src/lib/uiohook_worker.h +12 -0
@@ -0,0 +1,457 @@
1
+ /* libUIOHook: Cross-platform keyboard and mouse hooking from userland.
2
+ * Copyright (C) 2006-2023 Alexander Barker. All Rights Reserved.
3
+ * https://github.com/kwhat/libuiohook/
4
+ *
5
+ * libUIOHook is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU Lesser General Public License as published
7
+ * by the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * libUIOHook is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public License
16
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ #ifndef __UIOHOOK_H
20
+ #define __UIOHOOK_H
21
+
22
+ #include <stdarg.h>
23
+ #include <stdbool.h>
24
+ #include <stdint.h>
25
+
26
+ /* Begin Error Codes */
27
+ #define UIOHOOK_SUCCESS 0x00
28
+ #define UIOHOOK_FAILURE 0x01
29
+
30
+ // System level errors.
31
+ #define UIOHOOK_ERROR_OUT_OF_MEMORY 0x02
32
+
33
+ // Unix specific errors.
34
+ #define UIOHOOK_ERROR_X_OPEN_DISPLAY 0x20
35
+ #define UIOHOOK_ERROR_X_RECORD_NOT_FOUND 0x21
36
+ #define UIOHOOK_ERROR_X_RECORD_ALLOC_RANGE 0x22
37
+ #define UIOHOOK_ERROR_X_RECORD_CREATE_CONTEXT 0x23
38
+ #define UIOHOOK_ERROR_X_RECORD_ENABLE_CONTEXT 0x24
39
+ #define UIOHOOK_ERROR_X_RECORD_GET_CONTEXT 0x25
40
+
41
+ // Windows specific errors.
42
+ #define UIOHOOK_ERROR_SET_WINDOWS_HOOK_EX 0x30
43
+ #define UIOHOOK_ERROR_GET_MODULE_HANDLE 0x31
44
+
45
+ // Darwin specific errors.
46
+ #define UIOHOOK_ERROR_AXAPI_DISABLED 0x40
47
+ #define UIOHOOK_ERROR_CREATE_EVENT_PORT 0x41
48
+ #define UIOHOOK_ERROR_CREATE_RUN_LOOP_SOURCE 0x42
49
+ #define UIOHOOK_ERROR_GET_RUNLOOP 0x43
50
+ #define UIOHOOK_ERROR_CREATE_OBSERVER 0x44
51
+ /* End Error Codes */
52
+
53
+ /* Begin Log Levels and Function Prototype */
54
+ typedef enum _log_level {
55
+ LOG_LEVEL_DEBUG = 1,
56
+ LOG_LEVEL_INFO,
57
+ LOG_LEVEL_WARN,
58
+ LOG_LEVEL_ERROR
59
+ } log_level;
60
+
61
+ // Logger callback function prototype.
62
+ typedef bool (*logger_t)(unsigned int, const char *, ...);
63
+ /* End Log Levels and Function Prototype */
64
+
65
+ /* Begin Virtual Event Types and Data Structures */
66
+ typedef enum _event_type {
67
+ EVENT_HOOK_ENABLED = 1,
68
+ EVENT_HOOK_DISABLED,
69
+ EVENT_KEY_TYPED,
70
+ EVENT_KEY_PRESSED,
71
+ EVENT_KEY_RELEASED,
72
+ EVENT_MOUSE_CLICKED,
73
+ EVENT_MOUSE_PRESSED,
74
+ EVENT_MOUSE_RELEASED,
75
+ EVENT_MOUSE_MOVED,
76
+ EVENT_MOUSE_DRAGGED,
77
+ EVENT_MOUSE_WHEEL
78
+ } event_type;
79
+
80
+ typedef struct _screen_data {
81
+ uint8_t number;
82
+ int16_t x;
83
+ int16_t y;
84
+ uint16_t width;
85
+ uint16_t height;
86
+ } screen_data;
87
+
88
+ typedef struct _keyboard_event_data {
89
+ uint16_t keycode;
90
+ uint16_t rawcode;
91
+ uint16_t keychar;
92
+ } keyboard_event_data,
93
+ key_pressed_event_data,
94
+ key_released_event_data,
95
+ key_typed_event_data;
96
+
97
+ typedef struct _mouse_event_data {
98
+ uint16_t button;
99
+ uint16_t clicks;
100
+ int16_t x;
101
+ int16_t y;
102
+ } mouse_event_data,
103
+ mouse_pressed_event_data,
104
+ mouse_released_event_data,
105
+ mouse_clicked_event_data;
106
+
107
+ typedef struct _mouse_wheel_event_data {
108
+ uint16_t clicks;
109
+ int16_t x;
110
+ int16_t y;
111
+ uint8_t type;
112
+ uint16_t amount;
113
+ int16_t rotation;
114
+ uint8_t direction;
115
+ } mouse_wheel_event_data;
116
+
117
+ typedef struct _uiohook_event {
118
+ event_type type;
119
+ uint64_t time;
120
+ uint16_t mask;
121
+ uint16_t reserved;
122
+ union {
123
+ keyboard_event_data keyboard;
124
+ mouse_event_data mouse;
125
+ mouse_wheel_event_data wheel;
126
+ } data;
127
+ } uiohook_event;
128
+
129
+ typedef void (*dispatcher_t)(uiohook_event *const);
130
+ /* End Virtual Event Types and Data Structures */
131
+
132
+
133
+ /* Begin Virtual Key Codes */
134
+ #define VC_ESCAPE 0x0001
135
+
136
+ // Begin Function Keys
137
+ #define VC_F1 0x003B
138
+ #define VC_F2 0x003C
139
+ #define VC_F3 0x003D
140
+ #define VC_F4 0x003E
141
+ #define VC_F5 0x003F
142
+ #define VC_F6 0x0040
143
+ #define VC_F7 0x0041
144
+ #define VC_F8 0x0042
145
+ #define VC_F9 0x0043
146
+ #define VC_F10 0x0044
147
+ #define VC_F11 0x0057
148
+ #define VC_F12 0x0058
149
+
150
+ #define VC_F13 0x005B
151
+ #define VC_F14 0x005C
152
+ #define VC_F15 0x005D
153
+ #define VC_F16 0x0063
154
+ #define VC_F17 0x0064
155
+ #define VC_F18 0x0065
156
+ #define VC_F19 0x0066
157
+ #define VC_F20 0x0067
158
+ #define VC_F21 0x0068
159
+ #define VC_F22 0x0069
160
+ #define VC_F23 0x006A
161
+ #define VC_F24 0x006B
162
+ // End Function Keys
163
+
164
+
165
+ // Begin Alphanumeric Zone
166
+ #define VC_BACKQUOTE 0x0029
167
+
168
+ #define VC_1 0x0002
169
+ #define VC_2 0x0003
170
+ #define VC_3 0x0004
171
+ #define VC_4 0x0005
172
+ #define VC_5 0x0006
173
+ #define VC_6 0x0007
174
+ #define VC_7 0x0008
175
+ #define VC_8 0x0009
176
+ #define VC_9 0x000A
177
+ #define VC_0 0x000B
178
+
179
+ #define VC_MINUS 0x000C // '-'
180
+ #define VC_EQUALS 0x000D // '='
181
+ #define VC_BACKSPACE 0x000E
182
+
183
+ #define VC_TAB 0x000F
184
+ #define VC_CAPS_LOCK 0x003A
185
+
186
+ #define VC_A 0x001E
187
+ #define VC_B 0x0030
188
+ #define VC_C 0x002E
189
+ #define VC_D 0x0020
190
+ #define VC_E 0x0012
191
+ #define VC_F 0x0021
192
+ #define VC_G 0x0022
193
+ #define VC_H 0x0023
194
+ #define VC_I 0x0017
195
+ #define VC_J 0x0024
196
+ #define VC_K 0x0025
197
+ #define VC_L 0x0026
198
+ #define VC_M 0x0032
199
+ #define VC_N 0x0031
200
+ #define VC_O 0x0018
201
+ #define VC_P 0x0019
202
+ #define VC_Q 0x0010
203
+ #define VC_R 0x0013
204
+ #define VC_S 0x001F
205
+ #define VC_T 0x0014
206
+ #define VC_U 0x0016
207
+ #define VC_V 0x002F
208
+ #define VC_W 0x0011
209
+ #define VC_X 0x002D
210
+ #define VC_Y 0x0015
211
+ #define VC_Z 0x002C
212
+
213
+ #define VC_OPEN_BRACKET 0x001A // '['
214
+ #define VC_CLOSE_BRACKET 0x001B // ']'
215
+ #define VC_BACK_SLASH 0x002B // '\'
216
+
217
+ #define VC_SEMICOLON 0x0027 // ';'
218
+ #define VC_QUOTE 0x0028
219
+ #define VC_ENTER 0x001C
220
+
221
+ #define VC_COMMA 0x0033 // ','
222
+ #define VC_PERIOD 0x0034 // '.'
223
+ #define VC_SLASH 0x0035 // '/'
224
+
225
+ #define VC_SPACE 0x0039
226
+ // End Alphanumeric Zone
227
+
228
+
229
+ #define VC_PRINTSCREEN 0x0E37
230
+ #define VC_SCROLL_LOCK 0x0046
231
+ #define VC_PAUSE 0x0E45
232
+
233
+ #define VC_LESSER_GREATER 0x0E46 // '<', '>', '|' on qwertz layout
234
+
235
+ // Begin Edit Key Zone
236
+ #define VC_INSERT 0x0E52
237
+ #define VC_DELETE 0x0E53
238
+ #define VC_HOME 0x0E47
239
+ #define VC_END 0x0E4F
240
+ #define VC_PAGE_UP 0x0E49
241
+ #define VC_PAGE_DOWN 0x0E51
242
+ // End Edit Key Zone
243
+
244
+
245
+ // Begin Cursor Key Zone
246
+ #define VC_UP 0xE048
247
+ #define VC_LEFT 0xE04B
248
+ #define VC_CLEAR 0xE04C
249
+ #define VC_RIGHT 0xE04D
250
+ #define VC_DOWN 0xE050
251
+ // End Cursor Key Zone
252
+
253
+
254
+ // Begin Numeric Zone
255
+ #define VC_NUM_LOCK 0x0045
256
+ #define VC_KP_DIVIDE 0x0E35
257
+ #define VC_KP_MULTIPLY 0x0037
258
+ #define VC_KP_SUBTRACT 0x004A
259
+ #define VC_KP_EQUALS 0x0E0D
260
+ #define VC_KP_ADD 0x004E
261
+ #define VC_KP_ENTER 0x0E1C
262
+ #define VC_KP_SEPARATOR 0x0053
263
+
264
+ #define VC_KP_1 0x004F
265
+ #define VC_KP_2 0x0050
266
+ #define VC_KP_3 0x0051
267
+ #define VC_KP_4 0x004B
268
+ #define VC_KP_5 0x004C
269
+ #define VC_KP_6 0x004D
270
+ #define VC_KP_7 0x0047
271
+ #define VC_KP_8 0x0048
272
+ #define VC_KP_9 0x0049
273
+ #define VC_KP_0 0x0052
274
+
275
+ #define VC_KP_END 0xEE00 | VC_KP_1
276
+ #define VC_KP_DOWN 0xEE00 | VC_KP_2
277
+ #define VC_KP_PAGE_DOWN 0xEE00 | VC_KP_3
278
+ #define VC_KP_LEFT 0xEE00 | VC_KP_4
279
+ #define VC_KP_CLEAR 0xEE00 | VC_KP_5
280
+ #define VC_KP_RIGHT 0xEE00 | VC_KP_6
281
+ #define VC_KP_HOME 0xEE00 | VC_KP_7
282
+ #define VC_KP_UP 0xEE00 | VC_KP_8
283
+ #define VC_KP_PAGE_UP 0xEE00 | VC_KP_9
284
+ #define VC_KP_INSERT 0xEE00 | VC_KP_0
285
+ #define VC_KP_DELETE 0xEE00 | VC_KP_SEPARATOR
286
+ // End Numeric Zone
287
+
288
+
289
+ // Begin Modifier and Control Keys
290
+ #define VC_SHIFT_L 0x002A
291
+ #define VC_SHIFT_R 0x0036
292
+ #define VC_CONTROL_L 0x001D
293
+ #define VC_CONTROL_R 0x0E1D
294
+ #define VC_ALT_L 0x0038 // Option or Alt Key
295
+ #define VC_ALT_R 0x0E38 // Option or Alt Key
296
+ #define VC_META_L 0x0E5B // Windows or Command Key
297
+ #define VC_META_R 0x0E5C // Windows or Command Key
298
+ #define VC_CONTEXT_MENU 0x0E5D
299
+ // End Modifier and Control Keys
300
+
301
+
302
+ // Begin Media Control Keys
303
+ #define VC_POWER 0xE05E
304
+ #define VC_SLEEP 0xE05F
305
+ #define VC_WAKE 0xE063
306
+
307
+ #define VC_MEDIA_PLAY 0xE022
308
+ #define VC_MEDIA_STOP 0xE024
309
+ #define VC_MEDIA_PREVIOUS 0xE010
310
+ #define VC_MEDIA_NEXT 0xE019
311
+ #define VC_MEDIA_SELECT 0xE06D
312
+ #define VC_MEDIA_EJECT 0xE02C
313
+
314
+ #define VC_VOLUME_MUTE 0xE020
315
+ #define VC_VOLUME_UP 0xE030
316
+ #define VC_VOLUME_DOWN 0xE02E
317
+
318
+ #define VC_APP_MAIL 0xE06C
319
+ #define VC_APP_CALCULATOR 0xE021
320
+ #define VC_APP_MUSIC 0xE03C
321
+ #define VC_APP_PICTURES 0xE064
322
+
323
+ #define VC_BROWSER_SEARCH 0xE065
324
+ #define VC_BROWSER_HOME 0xE032
325
+ #define VC_BROWSER_BACK 0xE06A
326
+ #define VC_BROWSER_FORWARD 0xE069
327
+ #define VC_BROWSER_STOP 0xE068
328
+ #define VC_BROWSER_REFRESH 0xE067
329
+ #define VC_BROWSER_FAVORITES 0xE066
330
+ // End Media Control Keys
331
+
332
+ // Begin Japanese Language Keys
333
+ #define VC_KATAKANA 0x0070
334
+ #define VC_UNDERSCORE 0x0073
335
+ #define VC_FURIGANA 0x0077
336
+ #define VC_KANJI 0x0079
337
+ #define VC_HIRAGANA 0x007B
338
+ #define VC_YEN 0x007D
339
+ #define VC_KP_COMMA 0x007E
340
+ // End Japanese Language Keys
341
+
342
+ // Begin Sun keyboards
343
+ #define VC_SUN_HELP 0xFF75
344
+
345
+ #define VC_SUN_STOP 0xFF78
346
+ #define VC_SUN_PROPS 0xFF76
347
+ #define VC_SUN_FRONT 0xFF77
348
+ #define VC_SUN_OPEN 0xFF74
349
+ #define VC_SUN_FIND 0xFF7E
350
+ #define VC_SUN_AGAIN 0xFF79
351
+ #define VC_SUN_UNDO 0xFF7A
352
+ #define VC_SUN_COPY 0xFF7C
353
+ #define VC_SUN_INSERT 0xFF7D
354
+ #define VC_SUN_CUT 0xFF7B
355
+ // End Sun keyboards
356
+
357
+ #define VC_UNDEFINED 0x0000 // KeyCode Unknown
358
+
359
+ #define CHAR_UNDEFINED 0xFFFF // CharCode Unknown
360
+ /* End Virtual Key Codes */
361
+
362
+
363
+ /* Begin Virtual Modifier Masks */
364
+ #define MASK_SHIFT_L 1 << 0
365
+ #define MASK_CTRL_L 1 << 1
366
+ #define MASK_META_L 1 << 2
367
+ #define MASK_ALT_L 1 << 3
368
+
369
+ #define MASK_SHIFT_R 1 << 4
370
+ #define MASK_CTRL_R 1 << 5
371
+ #define MASK_META_R 1 << 6
372
+ #define MASK_ALT_R 1 << 7
373
+
374
+ #define MASK_SHIFT MASK_SHIFT_L | MASK_SHIFT_R
375
+ #define MASK_CTRL MASK_CTRL_L | MASK_CTRL_R
376
+ #define MASK_META MASK_META_L | MASK_META_R
377
+ #define MASK_ALT MASK_ALT_L | MASK_ALT_R
378
+
379
+ #define MASK_BUTTON1 1 << 8
380
+ #define MASK_BUTTON2 1 << 9
381
+ #define MASK_BUTTON3 1 << 10
382
+ #define MASK_BUTTON4 1 << 11
383
+ #define MASK_BUTTON5 1 << 12
384
+
385
+ #define MASK_NUM_LOCK 1 << 13
386
+ #define MASK_CAPS_LOCK 1 << 14
387
+ #define MASK_SCROLL_LOCK 1 << 15
388
+ /* End Virtual Modifier Masks */
389
+
390
+
391
+ /* Begin Virtual Mouse Buttons */
392
+ #define MOUSE_NOBUTTON 0 // Any Button
393
+ #define MOUSE_BUTTON1 1 // Left Button
394
+ #define MOUSE_BUTTON2 2 // Right Button
395
+ #define MOUSE_BUTTON3 3 // Middle Button
396
+ #define MOUSE_BUTTON4 4 // Extra Mouse Button
397
+ #define MOUSE_BUTTON5 5 // Extra Mouse Button
398
+
399
+ #define WHEEL_UNIT_SCROLL 1
400
+ #define WHEEL_BLOCK_SCROLL 2
401
+
402
+ #define WHEEL_VERTICAL_DIRECTION 3
403
+ #define WHEEL_HORIZONTAL_DIRECTION 4
404
+ /* End Virtual Mouse Buttons */
405
+
406
+
407
+ #ifdef _WIN32
408
+ #define UIOHOOK_API __declspec(dllexport)
409
+ #else
410
+ #define UIOHOOK_API
411
+ #endif
412
+
413
+ #ifdef __cplusplus
414
+ extern "C" {
415
+ #endif
416
+
417
+ // Set the logger callback functions.
418
+ UIOHOOK_API void hook_set_logger_proc(logger_t logger_proc);
419
+
420
+ // Send a virtual event back to the system.
421
+ UIOHOOK_API void hook_post_event(uiohook_event * const event);
422
+
423
+ // Set the event callback function.
424
+ UIOHOOK_API void hook_set_dispatch_proc(dispatcher_t dispatch_proc);
425
+
426
+ // Insert the event hook.
427
+ UIOHOOK_API int hook_run();
428
+
429
+ // Withdraw the event hook.
430
+ UIOHOOK_API int hook_stop();
431
+
432
+ // Retrieves an array of screen data for each available monitor.
433
+ UIOHOOK_API screen_data* hook_create_screen_info(unsigned char *count);
434
+
435
+ // Retrieves the keyboard auto repeat rate.
436
+ UIOHOOK_API long int hook_get_auto_repeat_rate();
437
+
438
+ // Retrieves the keyboard auto repeat delay.
439
+ UIOHOOK_API long int hook_get_auto_repeat_delay();
440
+
441
+ // Retrieves the mouse acceleration multiplier.
442
+ UIOHOOK_API long int hook_get_pointer_acceleration_multiplier();
443
+
444
+ // Retrieves the mouse acceleration threshold.
445
+ UIOHOOK_API long int hook_get_pointer_acceleration_threshold();
446
+
447
+ // Retrieves the mouse sensitivity.
448
+ UIOHOOK_API long int hook_get_pointer_sensitivity();
449
+
450
+ // Retrieves the double/triple click interval.
451
+ UIOHOOK_API long int hook_get_multi_click_time();
452
+
453
+ #ifdef __cplusplus
454
+ }
455
+ #endif
456
+
457
+ #endif