node-native-win-utils 1.4.0 → 2.1.1

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 (204) hide show
  1. package/README.md +29 -82
  2. package/binding.gyp +2 -0
  3. package/dist/dirnameLocal.cjs +4 -0
  4. package/dist/dirnameLocal.d.cts +1 -0
  5. package/dist/dirnameLocal.d.mts +1 -0
  6. package/dist/dirnameLocal.mjs +2 -0
  7. package/dist/{index.js → index.cjs} +83 -16
  8. package/dist/{index.d.ts → index.d.cts} +68 -17
  9. package/dist/index.d.mts +230 -0
  10. package/dist/index.mjs +212 -0
  11. package/dist/keyCodes.d.mts +101 -0
  12. package/dist/keyCodes.mjs +201 -0
  13. package/node22.json +16 -0
  14. package/package.json +19 -9
  15. package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
  16. package/src/cpp/keyboard.cpp +141 -140
  17. package/src/cpp/main.cpp +9 -3
  18. package/src/cpp/{capturewindow.cpp → screenshot.cpp} +174 -2
  19. package/src/dirnameLocal.mts +3 -0
  20. package/src/index.mts +455 -0
  21. package/src/keyCodes.mts +203 -0
  22. package/dllCopy.js +0 -14
  23. package/include/opencv2/core/affine.hpp +0 -678
  24. package/include/opencv2/core/async.hpp +0 -105
  25. package/include/opencv2/core/base.hpp +0 -664
  26. package/include/opencv2/core/bindings_utils.hpp +0 -325
  27. package/include/opencv2/core/bufferpool.hpp +0 -40
  28. package/include/opencv2/core/check.hpp +0 -170
  29. package/include/opencv2/core/core.hpp +0 -48
  30. package/include/opencv2/core/core_c.h +0 -3128
  31. package/include/opencv2/core/cuda/block.hpp +0 -211
  32. package/include/opencv2/core/cuda/border_interpolate.hpp +0 -722
  33. package/include/opencv2/core/cuda/color.hpp +0 -309
  34. package/include/opencv2/core/cuda/common.hpp +0 -131
  35. package/include/opencv2/core/cuda/datamov_utils.hpp +0 -113
  36. package/include/opencv2/core/cuda/detail/color_detail.hpp +0 -2018
  37. package/include/opencv2/core/cuda/detail/reduce.hpp +0 -365
  38. package/include/opencv2/core/cuda/detail/reduce_key_val.hpp +0 -502
  39. package/include/opencv2/core/cuda/detail/transform_detail.hpp +0 -392
  40. package/include/opencv2/core/cuda/detail/type_traits_detail.hpp +0 -191
  41. package/include/opencv2/core/cuda/detail/vec_distance_detail.hpp +0 -121
  42. package/include/opencv2/core/cuda/dynamic_smem.hpp +0 -88
  43. package/include/opencv2/core/cuda/emulation.hpp +0 -269
  44. package/include/opencv2/core/cuda/filters.hpp +0 -293
  45. package/include/opencv2/core/cuda/funcattrib.hpp +0 -79
  46. package/include/opencv2/core/cuda/functional.hpp +0 -805
  47. package/include/opencv2/core/cuda/limits.hpp +0 -128
  48. package/include/opencv2/core/cuda/reduce.hpp +0 -209
  49. package/include/opencv2/core/cuda/saturate_cast.hpp +0 -292
  50. package/include/opencv2/core/cuda/scan.hpp +0 -258
  51. package/include/opencv2/core/cuda/simd_functions.hpp +0 -869
  52. package/include/opencv2/core/cuda/transform.hpp +0 -75
  53. package/include/opencv2/core/cuda/type_traits.hpp +0 -90
  54. package/include/opencv2/core/cuda/utility.hpp +0 -230
  55. package/include/opencv2/core/cuda/vec_distance.hpp +0 -232
  56. package/include/opencv2/core/cuda/vec_math.hpp +0 -923
  57. package/include/opencv2/core/cuda/vec_traits.hpp +0 -288
  58. package/include/opencv2/core/cuda/warp.hpp +0 -139
  59. package/include/opencv2/core/cuda/warp_reduce.hpp +0 -76
  60. package/include/opencv2/core/cuda/warp_shuffle.hpp +0 -162
  61. package/include/opencv2/core/cuda.hpp +0 -1279
  62. package/include/opencv2/core/cuda.inl.hpp +0 -763
  63. package/include/opencv2/core/cuda_stream_accessor.hpp +0 -86
  64. package/include/opencv2/core/cuda_types.hpp +0 -144
  65. package/include/opencv2/core/cv_cpu_dispatch.h +0 -381
  66. package/include/opencv2/core/cv_cpu_helper.h +0 -550
  67. package/include/opencv2/core/cvdef.h +0 -973
  68. package/include/opencv2/core/cvstd.hpp +0 -190
  69. package/include/opencv2/core/cvstd.inl.hpp +0 -197
  70. package/include/opencv2/core/cvstd_wrapper.hpp +0 -154
  71. package/include/opencv2/core/detail/async_promise.hpp +0 -71
  72. package/include/opencv2/core/detail/dispatch_helper.impl.hpp +0 -49
  73. package/include/opencv2/core/detail/exception_ptr.hpp +0 -27
  74. package/include/opencv2/core/directx.hpp +0 -184
  75. package/include/opencv2/core/dualquaternion.hpp +0 -979
  76. package/include/opencv2/core/dualquaternion.inl.hpp +0 -487
  77. package/include/opencv2/core/eigen.hpp +0 -402
  78. package/include/opencv2/core/fast_math.hpp +0 -433
  79. package/include/opencv2/core/hal/hal.hpp +0 -256
  80. package/include/opencv2/core/hal/interface.h +0 -190
  81. package/include/opencv2/core/hal/intrin.hpp +0 -939
  82. package/include/opencv2/core/hal/intrin_avx.hpp +0 -3177
  83. package/include/opencv2/core/hal/intrin_avx512.hpp +0 -3090
  84. package/include/opencv2/core/hal/intrin_cpp.hpp +0 -3321
  85. package/include/opencv2/core/hal/intrin_forward.hpp +0 -191
  86. package/include/opencv2/core/hal/intrin_lasx.hpp +0 -3236
  87. package/include/opencv2/core/hal/intrin_msa.hpp +0 -1887
  88. package/include/opencv2/core/hal/intrin_neon.hpp +0 -2610
  89. package/include/opencv2/core/hal/intrin_rvv.hpp +0 -3320
  90. package/include/opencv2/core/hal/intrin_rvv071.hpp +0 -2545
  91. package/include/opencv2/core/hal/intrin_rvv_scalable.hpp +0 -2080
  92. package/include/opencv2/core/hal/intrin_sse.hpp +0 -3467
  93. package/include/opencv2/core/hal/intrin_sse_em.hpp +0 -180
  94. package/include/opencv2/core/hal/intrin_vsx.hpp +0 -1608
  95. package/include/opencv2/core/hal/intrin_wasm.hpp +0 -2782
  96. package/include/opencv2/core/hal/msa_macros.h +0 -1558
  97. package/include/opencv2/core/hal/simd_utils.impl.hpp +0 -186
  98. package/include/opencv2/core/llapi/llapi.h +0 -102
  99. package/include/opencv2/core/mat.hpp +0 -3775
  100. package/include/opencv2/core/mat.inl.hpp +0 -3422
  101. package/include/opencv2/core/matx.hpp +0 -1536
  102. package/include/opencv2/core/neon_utils.hpp +0 -128
  103. package/include/opencv2/core/ocl.hpp +0 -917
  104. package/include/opencv2/core/ocl_genbase.hpp +0 -69
  105. package/include/opencv2/core/opencl/ocl_defs.hpp +0 -82
  106. package/include/opencv2/core/opencl/opencl_info.hpp +0 -212
  107. package/include/opencv2/core/opencl/opencl_svm.hpp +0 -81
  108. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp +0 -602
  109. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp +0 -146
  110. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +0 -371
  111. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp +0 -272
  112. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +0 -62
  113. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +0 -42
  114. package/include/opencv2/core/opencl/runtime/opencl_clblas.hpp +0 -53
  115. package/include/opencv2/core/opencl/runtime/opencl_clfft.hpp +0 -53
  116. package/include/opencv2/core/opencl/runtime/opencl_core.hpp +0 -84
  117. package/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp +0 -47
  118. package/include/opencv2/core/opencl/runtime/opencl_gl.hpp +0 -53
  119. package/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp +0 -47
  120. package/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp +0 -48
  121. package/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp +0 -42
  122. package/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp +0 -166
  123. package/include/opencv2/core/opengl.hpp +0 -733
  124. package/include/opencv2/core/openvx/ovx_defs.hpp +0 -48
  125. package/include/opencv2/core/operations.hpp +0 -610
  126. package/include/opencv2/core/optim.hpp +0 -302
  127. package/include/opencv2/core/ovx.hpp +0 -28
  128. package/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +0 -72
  129. package/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +0 -153
  130. package/include/opencv2/core/parallel/parallel_backend.hpp +0 -90
  131. package/include/opencv2/core/persistence.hpp +0 -1350
  132. package/include/opencv2/core/private/cv_cpu_include_simd_declarations.hpp +0 -30
  133. package/include/opencv2/core/private.cuda.hpp +0 -169
  134. package/include/opencv2/core/private.hpp +0 -896
  135. package/include/opencv2/core/quaternion.hpp +0 -1696
  136. package/include/opencv2/core/quaternion.inl.hpp +0 -1063
  137. package/include/opencv2/core/saturate.hpp +0 -180
  138. package/include/opencv2/core/simd_intrinsics.hpp +0 -87
  139. package/include/opencv2/core/softfloat.hpp +0 -514
  140. package/include/opencv2/core/sse_utils.hpp +0 -652
  141. package/include/opencv2/core/traits.hpp +0 -417
  142. package/include/opencv2/core/types.hpp +0 -2457
  143. package/include/opencv2/core/types_c.h +0 -2126
  144. package/include/opencv2/core/utility.hpp +0 -1229
  145. package/include/opencv2/core/utils/allocator_stats.hpp +0 -29
  146. package/include/opencv2/core/utils/allocator_stats.impl.hpp +0 -158
  147. package/include/opencv2/core/utils/buffer_area.private.hpp +0 -136
  148. package/include/opencv2/core/utils/configuration.private.hpp +0 -22
  149. package/include/opencv2/core/utils/filesystem.hpp +0 -82
  150. package/include/opencv2/core/utils/filesystem.private.hpp +0 -66
  151. package/include/opencv2/core/utils/fp_control.private.hpp +0 -29
  152. package/include/opencv2/core/utils/fp_control_utils.hpp +0 -69
  153. package/include/opencv2/core/utils/instrumentation.hpp +0 -125
  154. package/include/opencv2/core/utils/lock.private.hpp +0 -119
  155. package/include/opencv2/core/utils/logger.defines.hpp +0 -42
  156. package/include/opencv2/core/utils/logger.hpp +0 -218
  157. package/include/opencv2/core/utils/logtag.hpp +0 -28
  158. package/include/opencv2/core/utils/plugin_loader.private.hpp +0 -165
  159. package/include/opencv2/core/utils/tls.hpp +0 -235
  160. package/include/opencv2/core/utils/trace.hpp +0 -252
  161. package/include/opencv2/core/utils/trace.private.hpp +0 -421
  162. package/include/opencv2/core/va_intel.hpp +0 -75
  163. package/include/opencv2/core/version.hpp +0 -26
  164. package/include/opencv2/core/vsx_utils.hpp +0 -1047
  165. package/include/opencv2/core.hpp +0 -3365
  166. package/include/opencv2/imgcodecs/imgcodecs.hpp +0 -48
  167. package/include/opencv2/imgcodecs/imgcodecs_c.h +0 -1
  168. package/include/opencv2/imgcodecs/ios.h +0 -59
  169. package/include/opencv2/imgcodecs/legacy/constants_c.h +0 -54
  170. package/include/opencv2/imgcodecs/macosx.h +0 -20
  171. package/include/opencv2/imgcodecs.hpp +0 -407
  172. package/include/opencv2/imgproc/bindings.hpp +0 -34
  173. package/include/opencv2/imgproc/detail/gcgraph.hpp +0 -395
  174. package/include/opencv2/imgproc/hal/hal.hpp +0 -246
  175. package/include/opencv2/imgproc/hal/interface.h +0 -46
  176. package/include/opencv2/imgproc/imgproc.hpp +0 -48
  177. package/include/opencv2/imgproc/imgproc_c.h +0 -1177
  178. package/include/opencv2/imgproc/segmentation.hpp +0 -141
  179. package/include/opencv2/imgproc/types_c.h +0 -659
  180. package/include/opencv2/imgproc.hpp +0 -5035
  181. package/include/opencv2/opencv_modules.hpp +0 -17
  182. package/include/tesseract/baseapi.h +0 -820
  183. package/include/tesseract/capi.h +0 -485
  184. package/include/tesseract/export.h +0 -37
  185. package/include/tesseract/ltrresultiterator.h +0 -235
  186. package/include/tesseract/ocrclass.h +0 -158
  187. package/include/tesseract/osdetect.h +0 -139
  188. package/include/tesseract/pageiterator.h +0 -364
  189. package/include/tesseract/publictypes.h +0 -281
  190. package/include/tesseract/renderer.h +0 -334
  191. package/include/tesseract/resultiterator.h +0 -250
  192. package/include/tesseract/tesseract.h +0 -40
  193. package/include/tesseract/unichar.h +0 -174
  194. package/include/tesseract/version.h +0 -34
  195. package/include/tesseract/version.h.in +0 -34
  196. package/libs/libjpeg-turbo.lib +0 -0
  197. package/libs/libpng.lib +0 -0
  198. package/libs/opencv_core470.lib +0 -0
  199. package/libs/opencv_imgcodecs470.lib +0 -0
  200. package/libs/opencv_imgproc470.lib +0 -0
  201. package/libs/tesseract.lib +0 -0
  202. package/libs/zlib.lib +0 -0
  203. /package/dist/{keyCodes.js → keyCodes.cjs} +0 -0
  204. /package/dist/{keyCodes.d.ts → keyCodes.d.cts} +0 -0
package/README.md CHANGED
@@ -67,9 +67,7 @@ To use the package, import the necessary functions, types, and classes:
67
67
 
68
68
  import {
69
69
 
70
- keyDownHandler,
71
-
72
- keyUpHandler,
70
+ KeyboardListener
73
71
 
74
72
  getWindowData,
75
73
 
@@ -93,38 +91,30 @@ OpenCV,
93
91
 
94
92
 
95
93
 
96
- ## Key Event Listeners
94
+ ## Keyboard Event Listener
97
95
 
98
96
 
99
97
 
100
- The package provides `keyDownHandler` and `keyUpHandler` functions, which allow you to register callbacks for key down and key up events, respectively. The callbacks receive the `keyCode` as a parameter:
98
+ The package provides KeyboardListener singletone class, which allow you to register event listeners for key down and key up events, respectively. The event callbacks receive the `keyCode` as a parameter:
101
99
 
102
100
 
103
101
 
104
102
  ```javascript
105
103
 
106
- keyDownHandler((keyCode) => {
107
-
108
- console.log("Key down:", keyCode);
109
-
110
- });
111
-
112
-
113
-
114
- // Key down: 8
115
-
116
-
117
-
118
- keyUpHandler((keyCode) => {
119
-
120
- console.log("Key up:", keyCode);
121
-
122
- });
123
-
124
-
125
-
126
- // Key up: 8
127
-
104
+ const listener = KeyboardListener.listener()
105
+
106
+ listener.on("keyDown", (data: {
107
+ keyCode: number;
108
+ keyName: string;
109
+ }) => {
110
+ //your code
111
+ })
112
+ listener.on("keyUp", (data: {
113
+ keyCode: number;
114
+ keyName: string;
115
+ }) => {
116
+ //your code
117
+ })
128
118
  ```
129
119
 
130
120
  ## Key Press
@@ -473,18 +463,16 @@ Writes the current image to a file specified by the `path`.
473
463
 
474
464
  | Function | Parameters | Return Type |
475
465
  |-----------------|----------------------------------------------------------------------------------------------|-------------|
476
- | keyDownHandler | `callback: (keyCode: number) => void` | `void` |
477
- | keyUpHandler | `callback: (keyCode: number) => void` | `void` |
478
- | getWindowData | `windowName: string` | `WindowData`|
466
+ | getWindowData | `windowName: string` | `WindowData`|
479
467
  | captureWindow | `windowName: string, outputPath: string` | `void` |
480
468
  | mouseMove | `posX: number, posY: number` | `boolean` |
481
469
  | mouseClick | `button?: "left" \| "middle" \| "right"` | `boolean` |
482
- | mouseDrag | `startX: number, startY: number, endX: number, endY: number, speed?: number` | `boolean` |
470
+ | mouseDrag | `startX: number, startY: number, endX: number, endY: number, speed?: number` | `boolean` |
483
471
  | typeString | `stringToType: string, delay?: number` | `boolean` |
484
- | captureWindowN | `windowName: string` | `Buffer` |
485
- | keyPress | `keyCode: number, repeat?: number` | `boolean` |
486
-
487
-
472
+ | captureWindowN | `windowName: string` | `Buffer` |
473
+ | keyPress | `keyCode: number, repeat?: number` | `boolean` |
474
+ | textRecognition | `trainedDataPath: string, dataLang: string, imagePath: string` | `string` |
475
+ | captureScreenToFile | `path: string` | `boolean` |
488
476
 
489
477
 
490
478
  ## Examples
@@ -493,7 +481,10 @@ Writes the current image to a file specified by the `path`.
493
481
 
494
482
  Here are some examples of using the package:
495
483
 
496
-
484
+ ```javascript
485
+ console.log(textRecognition(path.join(__dirname, 'traineddata'), 'eng', path.join(__dirname, 'images', '1.jpg'))) // ---> <recognized text>
486
+
487
+ ```
497
488
 
498
489
  ```javascript
499
490
 
@@ -577,10 +568,6 @@ Please note that the above example demonstrates the usage of different methods a
577
568
 
578
569
  import {
579
570
 
580
- keyDownHandler,
581
-
582
- keyUpHandler,
583
-
584
571
  getWindowData,
585
572
 
586
573
  captureWindow,
@@ -599,34 +586,6 @@ KeyListener,
599
586
 
600
587
 
601
588
 
602
- // Register key event handlers
603
-
604
-
605
-
606
- keyDownHandler((keyCode) => {
607
-
608
- console.log("Key down:", keyCode);
609
-
610
- });
611
-
612
-
613
-
614
- // Key down: 123
615
-
616
-
617
-
618
- keyUpHandler((keyCode) => {
619
-
620
- console.log("Key up:", keyCode);
621
-
622
- });
623
-
624
-
625
-
626
- // Key up: 123
627
-
628
-
629
-
630
589
  // Retrieve window data
631
590
 
632
591
 
@@ -699,11 +658,11 @@ typeString("Hello, world!", 100); // Type with a delay of 100ms between characte
699
658
 
700
659
 
701
660
 
702
- // Use KeyListener class
661
+ // Use KeyboardListener class
703
662
 
704
663
 
705
664
 
706
- const listener = new KeyListener();
665
+ const listener = KeyboardListener.listener();
707
666
 
708
667
 
709
668
 
@@ -734,18 +693,6 @@ console.log("Key up:", data.keyCode, data.keyName);
734
693
 
735
694
  ```
736
695
 
737
- # TODO
738
-
739
-
740
-
741
- - Write proper tests
742
-
743
- - Add more useful functions
744
-
745
- - Fix issue with Windows scale for font,text,apps
746
-
747
-
748
-
749
696
  [OpenCV License](https://github.com/opencv/opencv/blob/master/LICENSE)
750
697
  [MIT License](https://github.com/T-Rumibul/node-native-win-utils/blob/main/LICENSE)
751
698
 
package/binding.gyp CHANGED
@@ -17,6 +17,8 @@
17
17
  "libraries": [
18
18
  "dwmapi.lib",
19
19
  "windowsapp.lib",
20
+ "-lgdi32",
21
+ "-lgdiplus",
20
22
  "<!(node -p \"require('path').resolve('libs/libjpeg-turbo.lib')\")",
21
23
  "<!(node -p \"require('path').resolve('libs/libpng.lib')\")",
22
24
  "<!(node -p \"require('path').resolve('libs/zlib.lib')\")",
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.__dirnameLocal = void 0;
4
+ exports.__dirnameLocal = __dirname;
@@ -0,0 +1 @@
1
+ export declare const __dirnameLocal: string;
@@ -0,0 +1 @@
1
+ export declare const __dirnameLocal: string;
@@ -0,0 +1,2 @@
1
+ import * as url from 'url';
2
+ export const __dirnameLocal = url.fileURLToPath(new URL('.', import.meta.url));
@@ -3,20 +3,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.textRecognition = exports.KeyCodeHelper = exports.rawPressKey = exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.getWindowData = exports.keyUpHandler = exports.keyDownHandler = exports.OpenCV = exports.KeyListener = void 0;
6
+ exports.OpenCV = exports.KeyboardListener = exports.captureScreenAsync = exports.textRecognition = exports.KeyCodeHelper = exports.rawPressKey = exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.getWindowData = void 0;
7
7
  exports.captureWindow = captureWindow;
8
8
  exports.keyPress = keyPress;
9
- const EventEmitter = require("events");
9
+ exports.captureScreenToFile = captureScreenToFile;
10
+ //@ts-nocheck
11
+ const events_1 = __importDefault(require("events"));
10
12
  const path_1 = __importDefault(require("path"));
11
13
  const fs_1 = __importDefault(require("fs"));
12
- const bindings = require("node-gyp-build")(path_1.default.resolve(__dirname, ".."));
13
- const keyCodes_1 = require("./keyCodes");
14
- Object.defineProperty(exports, "KeyCodeHelper", { enumerable: true, get: function () { return keyCodes_1.KeyCodeHelper; } });
15
- const { keyDownHandler, keyUpHandler, getWindowData, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition } = bindings;
16
- exports.keyDownHandler = keyDownHandler;
17
- exports.keyUpHandler = keyUpHandler;
14
+ // @ts-ignore
15
+ const nodeGypBuild = require("node-gyp-build");
16
+ const keyCodes_cjs_1 = require("./keyCodes.cjs");
17
+ Object.defineProperty(exports, "KeyCodeHelper", { enumerable: true, get: function () { return keyCodes_cjs_1.KeyCodeHelper; } });
18
+ const dirnameLocal_cjs_1 = require("./dirnameLocal.cjs");
19
+ const bindings = nodeGypBuild(path_1.default.resolve(dirnameLocal_cjs_1.__dirnameLocal, ".."));
20
+ const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition } = bindings;
18
21
  exports.getWindowData = getWindowData;
19
22
  exports.captureWindowN = captureWindowN;
23
+ exports.captureScreenAsync = captureScreenAsync;
20
24
  exports.mouseMove = mouseMove;
21
25
  exports.mouseClick = mouseClick;
22
26
  exports.mouseDrag = mouseDrag;
@@ -38,21 +42,51 @@ function captureWindow(windowName, path) {
38
42
  return true;
39
43
  }
40
44
  /**
41
- * Represents a class to listen to keyboard events.
45
+ * Captures a screen and saves it to a file.
46
+ * @param path - The file path to save the captured image.
47
+ * @returns True if the capture and save operation is successful, otherwise false.
48
+ */
49
+ function captureScreenToFile(path) {
50
+ return new Promise((resolve, reject) => {
51
+ captureScreenAsync().then((buffer) => {
52
+ fs_1.default.writeFileSync(path, new Uint8Array(buffer));
53
+ resolve(true);
54
+ }).catch((err => {
55
+ reject(err);
56
+ }));
57
+ });
58
+ }
59
+ /**
60
+ * Class that implements a private keyboard listener.
61
+ * This class leverages native C++ bindings to hook into system keyboard events.
62
+ * The C++ layer uses global ThreadSafeFunction objects to safely dispatch events
63
+ * (using a dedicated monitoring thread, mutexes, and atomic flags) to JavaScript.
42
64
  * @extends EventEmitter
43
65
  */
44
- class KeyListener extends EventEmitter {
66
+ class KeyboardListenerPrivate extends events_1.default {
67
+ /**
68
+ * Constructs the keyboard listener and sets up native callbacks.
69
+ * The callbacks (set via setKeyDownCallback and setKeyUpCallback) are defined in the
70
+ * C++ binding layer. They are responsible for invoking these JavaScript callbacks
71
+ * in a thread-safe manner once a key event is detected.
72
+ */
45
73
  constructor() {
46
74
  super();
47
- keyDownHandler((keyCode) => {
48
- const keyName = keyCodes_1.keyCodes.get(keyCode.toString());
75
+ // Set the callback for key down events.
76
+ setKeyDownCallback((keyCode) => {
77
+ // Look up the human-readable key name from a mapping.
78
+ const keyName = keyCodes_cjs_1.keyCodes.get(keyCode.toString());
79
+ // Emit the 'keyDown' event to all registered JavaScript listeners.
49
80
  this.emit("keyDown", {
50
81
  keyCode,
51
82
  keyName,
52
83
  });
53
84
  });
54
- keyUpHandler((keyCode) => {
55
- const keyName = keyCodes_1.keyCodes.get(keyCode.toString());
85
+ // Set the callback for key up events.
86
+ setKeyUpCallback((keyCode) => {
87
+ // Look up the human-readable key name from a mapping.
88
+ const keyName = keyCodes_cjs_1.keyCodes.get(keyCode.toString());
89
+ // Emit the 'keyUp' event to all registered JavaScript listeners.
56
90
  this.emit("keyUp", {
57
91
  keyCode,
58
92
  keyName,
@@ -60,7 +94,40 @@ class KeyListener extends EventEmitter {
60
94
  });
61
95
  }
62
96
  }
63
- exports.KeyListener = KeyListener;
97
+ /**
98
+ * A singleton manager for the KeyboardListenerPrivate instance.
99
+ * This class ensures that only one native keyboard listener is active at any time.
100
+ * When the listener is destroyed, it calls unsetKeyDownCallback and unsetKeyUpCallback
101
+ * to clean up native resources, mirroring the cleanup logic in the C++ bindings.
102
+ */
103
+ class KeyboardListener {
104
+ /**
105
+ * Holds the singleton instance of KeyboardListenerPrivate.
106
+ */
107
+ static listenerInstance = null;
108
+ /**
109
+ * Returns the singleton instance of KeyboardListenerPrivate. If not already created,
110
+ * it instantiates a new instance and sets up the native callbacks.
111
+ * @returns The active KeyboardListenerPrivate instance.
112
+ */
113
+ static listener() {
114
+ if (!this.listenerInstance) {
115
+ this.listenerInstance = new KeyboardListenerPrivate();
116
+ }
117
+ return this.listenerInstance;
118
+ }
119
+ /**
120
+ * Destroys the current KeyboardListenerPrivate instance and cleans up native callbacks.
121
+ * This method calls unsetKeyDownCallback and unsetKeyUpCallback to release any
122
+ * native resources (such as the global ThreadSafeFunctions) and stops the monitoring thread.
123
+ */
124
+ static destroy() {
125
+ this.listenerInstance = null;
126
+ unsetKeyDownCallback();
127
+ unsetKeyUpCallback();
128
+ }
129
+ }
130
+ exports.KeyboardListener = KeyboardListener;
64
131
  /**
65
132
  * Represents the OpenCV class that provides image processing functionality.
66
133
  */
@@ -154,7 +221,7 @@ function keyPress(keyCode, repeat) {
154
221
  reject('Something went wrong');
155
222
  return resolve(true);
156
223
  }
157
- for (let i = 0; i < repeat; i++) {
224
+ for (let i = 0; i <= repeat; i++) {
158
225
  let result = rawPressKey(keyCode);
159
226
  if (!result)
160
227
  reject('Something went wrong');
@@ -1,5 +1,5 @@
1
- import EventEmitter = require("events");
2
- import { KeyCodeHelper } from "./keyCodes";
1
+ import EventEmitter from 'events';
2
+ import { KeyCodeHelper } from "./keyCodes.cjs";
3
3
  /**
4
4
  * Represents the data of a window.
5
5
  */
@@ -35,15 +35,15 @@ export type MatchData = {
35
35
  export type GetWindowData = (windowName: string) => WindowData;
36
36
  export type CaptureWindow = (windowName: string) => Buffer;
37
37
  /**
38
- * The handler to listen to key-down events.
38
+ * The handler to listen to key-events.
39
39
  * @param callback - The callback function to handle key-down events.
40
40
  */
41
- export type KeyDownHandler = (callback: (keyCode: number) => void) => void;
41
+ export type SetKeyCallback = (callback: (keyCode: number) => void) => void;
42
42
  /**
43
- * The handler to listen to key-up events.
44
- * @param callback - The callback function to handle key-up events.
43
+ * The handler to stop thread listening to key-events.
44
+ * @param callback - The callback function to handle key-down events.
45
45
  */
46
- export type KeyUpHandler = (callback: (keyCode: number) => void) => void;
46
+ export type UnsetKeyCallback = () => void;
47
47
  /**
48
48
  * Function type for moving the mouse.
49
49
  */
@@ -81,7 +81,8 @@ export type BgrToGray = (image: ImageData) => ImageData;
81
81
  export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
82
82
  export type GetRegion = (image: ImageData, region: ROI) => ImageData;
83
83
  export type TextRecognition = (trainedDataPath: string, dataLang: string, imagePath: string) => string;
84
- declare const keyDownHandler: KeyDownHandler, keyUpHandler: KeyUpHandler, getWindowData: GetWindowData, captureWindowN: CaptureWindow, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
84
+ export type CaptureScreenAsync = () => Promise<Buffer>;
85
+ declare const getWindowData: GetWindowData, captureWindowN: CaptureWindow, captureScreenAsync: CaptureScreenAsync, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
85
86
  declare const rawPressKey: PressKey;
86
87
  /**
87
88
  * Captures a window and saves it to a file.
@@ -90,20 +91,37 @@ declare const rawPressKey: PressKey;
90
91
  * @returns True if the capture and save operation is successful, otherwise false.
91
92
  */
92
93
  declare function captureWindow(windowName: string, path: string): boolean;
93
- export interface KeyListener extends EventEmitter {
94
+ /**
95
+ * Captures a screen and saves it to a file.
96
+ * @param path - The file path to save the captured image.
97
+ * @returns True if the capture and save operation is successful, otherwise false.
98
+ */
99
+ declare function captureScreenToFile(path: string): Promise<boolean>;
100
+ /**
101
+ * Interface representing a private keyboard listener that extends EventEmitter.
102
+ * It declares event handlers for native keyboard events, which are forwarded from
103
+ * the C++ bindings using thread-safe callbacks.
104
+ */
105
+ interface KeyboardListenerPrivate extends EventEmitter {
94
106
  /**
95
- * Event: Fires when a key is pressed down.
107
+ * Registers an event handler for the 'keyDown' event.
108
+ * This event is fired when a key is pressed down. The C++ native binding calls
109
+ * this callback using a thread-safe mechanism (via Napi::ThreadSafeFunction).
96
110
  * @param event - The event name ('keyDown').
97
- * @param callback - The callback function to handle the event.
111
+ * @param callback - Function invoked with an object containing the keyCode and keyName.
112
+ * @returns The current instance for method chaining.
98
113
  */
99
114
  on(event: "keyDown", callback: (data: {
100
115
  keyCode: number;
101
116
  keyName: string;
102
117
  }) => void): this;
103
118
  /**
104
- * Event: Fires when a key is released.
119
+ * Registers an event handler for the 'keyUp' event.
120
+ * This event is fired when a key is released. The underlying C++ code safely
121
+ * invokes this callback from a background thread using a thread-safe function.
105
122
  * @param event - The event name ('keyUp').
106
- * @param callback - The callback function to handle the event.
123
+ * @param callback - Function invoked with an object containing the keyCode and keyName.
124
+ * @returns The current instance for method chaining.
107
125
  */
108
126
  on(event: "keyUp", callback: (data: {
109
127
  keyCode: number;
@@ -111,16 +129,49 @@ export interface KeyListener extends EventEmitter {
111
129
  }) => void): this;
112
130
  }
113
131
  /**
114
- * Represents a class to listen to keyboard events.
132
+ * Class that implements a private keyboard listener.
133
+ * This class leverages native C++ bindings to hook into system keyboard events.
134
+ * The C++ layer uses global ThreadSafeFunction objects to safely dispatch events
135
+ * (using a dedicated monitoring thread, mutexes, and atomic flags) to JavaScript.
115
136
  * @extends EventEmitter
116
137
  */
117
- export declare class KeyListener extends EventEmitter {
138
+ declare class KeyboardListenerPrivate extends EventEmitter {
139
+ /**
140
+ * Constructs the keyboard listener and sets up native callbacks.
141
+ * The callbacks (set via setKeyDownCallback and setKeyUpCallback) are defined in the
142
+ * C++ binding layer. They are responsible for invoking these JavaScript callbacks
143
+ * in a thread-safe manner once a key event is detected.
144
+ */
118
145
  constructor();
119
146
  }
147
+ /**
148
+ * A singleton manager for the KeyboardListenerPrivate instance.
149
+ * This class ensures that only one native keyboard listener is active at any time.
150
+ * When the listener is destroyed, it calls unsetKeyDownCallback and unsetKeyUpCallback
151
+ * to clean up native resources, mirroring the cleanup logic in the C++ bindings.
152
+ */
153
+ declare class KeyboardListener {
154
+ /**
155
+ * Holds the singleton instance of KeyboardListenerPrivate.
156
+ */
157
+ private static listenerInstance;
158
+ /**
159
+ * Returns the singleton instance of KeyboardListenerPrivate. If not already created,
160
+ * it instantiates a new instance and sets up the native callbacks.
161
+ * @returns The active KeyboardListenerPrivate instance.
162
+ */
163
+ static listener(): KeyboardListenerPrivate;
164
+ /**
165
+ * Destroys the current KeyboardListenerPrivate instance and cleans up native callbacks.
166
+ * This method calls unsetKeyDownCallback and unsetKeyUpCallback to release any
167
+ * native resources (such as the global ThreadSafeFunctions) and stops the monitoring thread.
168
+ */
169
+ static destroy(): void;
170
+ }
120
171
  /**
121
172
  * Represents the OpenCV class that provides image processing functionality.
122
173
  */
123
- export declare class OpenCV {
174
+ declare class OpenCV {
124
175
  imageData: ImageData;
125
176
  /**
126
177
  * Represents the OpenCV class that provides image processing functionality.
@@ -176,4 +227,4 @@ export declare class OpenCV {
176
227
  imwrite(path: string): void;
177
228
  }
178
229
  declare function keyPress(keyCode: number, repeat?: number): Promise<boolean>;
179
- export { keyDownHandler, keyUpHandler, getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition };
230
+ export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, captureScreenAsync, KeyboardListener, OpenCV };