node-native-win-utils 1.4.0 → 2.1.0

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} +46 -15
  8. package/dist/{index.d.ts → index.d.cts} +24 -12
  9. package/dist/index.d.mts +191 -0
  10. package/dist/index.mjs +177 -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 +454 -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,18 +3,21 @@ 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.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;
20
23
  exports.mouseMove = mouseMove;
@@ -37,22 +40,37 @@ function captureWindow(windowName, path) {
37
40
  fs_1.default.writeFileSync(path, new Uint8Array(buffer));
38
41
  return true;
39
42
  }
43
+ /**
44
+ * Captures a screen and saves it to a file.
45
+ * @param path - The file path to save the captured image.
46
+ * @returns True if the capture and save operation is successful, otherwise false.
47
+ */
48
+ function captureScreenToFile(path) {
49
+ return new Promise((resolve, reject) => {
50
+ captureScreenAsync().then((buffer) => {
51
+ fs_1.default.writeFileSync(path, new Uint8Array(buffer));
52
+ resolve(true);
53
+ }).catch((err => {
54
+ reject(err);
55
+ }));
56
+ });
57
+ }
40
58
  /**
41
59
  * Represents a class to listen to keyboard events.
42
60
  * @extends EventEmitter
43
61
  */
44
- class KeyListener extends EventEmitter {
62
+ class KeyboardListenerPrivate extends events_1.default {
45
63
  constructor() {
46
64
  super();
47
- keyDownHandler((keyCode) => {
48
- const keyName = keyCodes_1.keyCodes.get(keyCode.toString());
65
+ setKeyDownCallback((keyCode) => {
66
+ const keyName = keyCodes_cjs_1.keyCodes.get(keyCode.toString());
49
67
  this.emit("keyDown", {
50
68
  keyCode,
51
69
  keyName,
52
70
  });
53
71
  });
54
- keyUpHandler((keyCode) => {
55
- const keyName = keyCodes_1.keyCodes.get(keyCode.toString());
72
+ setKeyUpCallback((keyCode) => {
73
+ const keyName = keyCodes_cjs_1.keyCodes.get(keyCode.toString());
56
74
  this.emit("keyUp", {
57
75
  keyCode,
58
76
  keyName,
@@ -60,7 +78,20 @@ class KeyListener extends EventEmitter {
60
78
  });
61
79
  }
62
80
  }
63
- exports.KeyListener = KeyListener;
81
+ class KeyboardListener {
82
+ static listenerInstance = null;
83
+ static listener() {
84
+ if (!this.listenerInstance)
85
+ this.listenerInstance = new KeyboardListenerPrivate();
86
+ return this.listenerInstance;
87
+ }
88
+ static destroy() {
89
+ this.listenerInstance = null;
90
+ unsetKeyDownCallback();
91
+ unsetKeyUpCallback();
92
+ }
93
+ }
94
+ exports.KeyboardListener = KeyboardListener;
64
95
  /**
65
96
  * Represents the OpenCV class that provides image processing functionality.
66
97
  */
@@ -154,7 +185,7 @@ function keyPress(keyCode, repeat) {
154
185
  reject('Something went wrong');
155
186
  return resolve(true);
156
187
  }
157
- for (let i = 0; i < repeat; i++) {
188
+ for (let i = 0; i <= repeat; i++) {
158
189
  let result = rawPressKey(keyCode);
159
190
  if (!result)
160
191
  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, 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,7 +91,13 @@ 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
+ interface KeyboardListenerPrivate extends EventEmitter {
94
101
  /**
95
102
  * Event: Fires when a key is pressed down.
96
103
  * @param event - The event name ('keyDown').
@@ -114,13 +121,18 @@ export interface KeyListener extends EventEmitter {
114
121
  * Represents a class to listen to keyboard events.
115
122
  * @extends EventEmitter
116
123
  */
117
- export declare class KeyListener extends EventEmitter {
124
+ declare class KeyboardListenerPrivate extends EventEmitter {
118
125
  constructor();
119
126
  }
127
+ declare class KeyboardListener {
128
+ private static listenerInstance;
129
+ static listener(): KeyboardListenerPrivate;
130
+ static destroy(): void;
131
+ }
120
132
  /**
121
133
  * Represents the OpenCV class that provides image processing functionality.
122
134
  */
123
- export declare class OpenCV {
135
+ declare class OpenCV {
124
136
  imageData: ImageData;
125
137
  /**
126
138
  * Represents the OpenCV class that provides image processing functionality.
@@ -176,4 +188,4 @@ export declare class OpenCV {
176
188
  imwrite(path: string): void;
177
189
  }
178
190
  declare function keyPress(keyCode: number, repeat?: number): Promise<boolean>;
179
- export { keyDownHandler, keyUpHandler, getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition };
191
+ export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, KeyboardListener, OpenCV };
@@ -0,0 +1,191 @@
1
+ import EventEmitter from 'events';
2
+ import { KeyCodeHelper } from "./keyCodes.mjs";
3
+ /**
4
+ * Represents the data of a window.
5
+ */
6
+ export type WindowData = {
7
+ width: number;
8
+ height: number;
9
+ x: number;
10
+ y: number;
11
+ };
12
+ /**
13
+ * Represents the data of an image.
14
+ */
15
+ export type ImageData = {
16
+ width: number;
17
+ height: number;
18
+ data: Uint8Array;
19
+ };
20
+ /**
21
+ * Represents the result of a template matching operation.
22
+ */
23
+ export type MatchData = {
24
+ minValue: number;
25
+ maxValue: number;
26
+ minLocation: {
27
+ x: number;
28
+ y: number;
29
+ };
30
+ maxLocation: {
31
+ x: number;
32
+ y: number;
33
+ };
34
+ };
35
+ export type GetWindowData = (windowName: string) => WindowData;
36
+ export type CaptureWindow = (windowName: string) => Buffer;
37
+ /**
38
+ * The handler to listen to key-events.
39
+ * @param callback - The callback function to handle key-down events.
40
+ */
41
+ export type SetKeyCallback = (callback: (keyCode: number) => void) => void;
42
+ /**
43
+ * The handler to stop thread listening to key-events.
44
+ * @param callback - The callback function to handle key-down events.
45
+ */
46
+ export type UnsetKeyCallback = () => void;
47
+ /**
48
+ * Function type for moving the mouse.
49
+ */
50
+ export type MouseMove = (posX: number, posY: number) => boolean;
51
+ /**
52
+ * Function type for simulating a mouse click.
53
+ */
54
+ export type MouseClick = (button?: "left" | "middle" | "right") => boolean;
55
+ /**
56
+ * Function type for simulating typing.
57
+ */
58
+ export type TypeString = (stringToType: string, delay?: number) => boolean;
59
+ /**
60
+ * Function type for simulating key press and release.
61
+ */
62
+ export type PressKey = (keyCode: number) => boolean;
63
+ /**
64
+ * Function type for simulating a mouse drag operation.
65
+ */
66
+ export type MouseDrag = (starX: number, startY: number, endX: Number, endY: number, speed?: number) => boolean;
67
+ /**
68
+ * Represents a point in a two-dimensional space.
69
+ */
70
+ export type Point = [x: number, y: number];
71
+ export type Color = [r: number, g: number, b: number];
72
+ /**
73
+ * Represents a region of interest in an image.
74
+ */
75
+ export type ROI = [x: number, y: number, width: number, height: number];
76
+ export type Imread = (path: string) => ImageData;
77
+ export type Imwrite = (image: ImageData) => Buffer;
78
+ export type MatchTemplate = (image: ImageData, template: ImageData, method?: number | null, mask?: ImageData) => MatchData;
79
+ export type Blur = (image: ImageData, sizeX: number, sizeY: number) => ImageData;
80
+ export type BgrToGray = (image: ImageData) => ImageData;
81
+ export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
82
+ export type GetRegion = (image: ImageData, region: ROI) => ImageData;
83
+ export type TextRecognition = (trainedDataPath: string, dataLang: string, imagePath: string) => string;
84
+ export type CaptureScreenAsync = () => Promise<Buffer>;
85
+ declare const getWindowData: GetWindowData, captureWindowN: CaptureWindow, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
86
+ declare const rawPressKey: PressKey;
87
+ /**
88
+ * Captures a window and saves it to a file.
89
+ * @param windowName - The name of the window to capture.
90
+ * @param path - The file path to save the captured image.
91
+ * @returns True if the capture and save operation is successful, otherwise false.
92
+ */
93
+ declare function captureWindow(windowName: string, path: string): boolean;
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
+ interface KeyboardListenerPrivate extends EventEmitter {
101
+ /**
102
+ * Event: Fires when a key is pressed down.
103
+ * @param event - The event name ('keyDown').
104
+ * @param callback - The callback function to handle the event.
105
+ */
106
+ on(event: "keyDown", callback: (data: {
107
+ keyCode: number;
108
+ keyName: string;
109
+ }) => void): this;
110
+ /**
111
+ * Event: Fires when a key is released.
112
+ * @param event - The event name ('keyUp').
113
+ * @param callback - The callback function to handle the event.
114
+ */
115
+ on(event: "keyUp", callback: (data: {
116
+ keyCode: number;
117
+ keyName: string;
118
+ }) => void): this;
119
+ }
120
+ /**
121
+ * Represents a class to listen to keyboard events.
122
+ * @extends EventEmitter
123
+ */
124
+ declare class KeyboardListenerPrivate extends EventEmitter {
125
+ constructor();
126
+ }
127
+ declare class KeyboardListener {
128
+ private static listenerInstance;
129
+ static listener(): KeyboardListenerPrivate;
130
+ static destroy(): void;
131
+ }
132
+ /**
133
+ * Represents the OpenCV class that provides image processing functionality.
134
+ */
135
+ declare class OpenCV {
136
+ imageData: ImageData;
137
+ /**
138
+ * Represents the OpenCV class that provides image processing functionality.
139
+ */
140
+ constructor(image: string | ImageData);
141
+ /**
142
+ * The width of the image.
143
+ */
144
+ get width(): number;
145
+ /**
146
+ * The height of the image.
147
+ */
148
+ get height(): number;
149
+ /**
150
+ * Matches a template image within the current image.
151
+ * @param template - The template image data to search for.
152
+ * @param method - The template matching method (optional).
153
+ * @param mask - The optional mask image data to apply the operation (optional).
154
+ * @returns The result of the template matching operation.
155
+ */
156
+ matchTemplate(template: ImageData, method?: number | null, mask?: ImageData): MatchData;
157
+ /**
158
+ * Applies a blur filter to the image.
159
+ * @param sizeX - The horizontal size of the blur filter.
160
+ * @param sizeY - The vertical size of the blur filter.
161
+ * @returns A new OpenCV instance with the blurred image data.
162
+ */
163
+ blur(sizeX: number, sizeY: number): OpenCV;
164
+ /**
165
+ * Converts the image from BGR to grayscale.
166
+ * @returns A new OpenCV instance with the grayscale image data.
167
+ */
168
+ bgrToGray(): OpenCV;
169
+ /**
170
+ * Draws a rectangle on the image.
171
+ * @param start - The starting point of the rectangle.
172
+ * @param end - The ending point of the rectangle.
173
+ * @param rgb - The color (RGB) of the rectangle.
174
+ * @param thickness - The thickness of the rectangle's border.
175
+ * @returns A new OpenCV instance with the image containing the drawn rectangle.
176
+ */
177
+ drawRectangle(start: Point, end: Point, rgb: Color, thickness: number): OpenCV;
178
+ /**
179
+ * Extracts a region of interest (ROI) from the image.
180
+ * @param region - The region of interest defined as [x, y, width, height].
181
+ * @returns A new OpenCV instance with the extracted region of interest.
182
+ */
183
+ getRegion(region: ROI): OpenCV;
184
+ /**
185
+ * Writes the image data to a file.
186
+ * @param path - The file path to save the image.
187
+ */
188
+ imwrite(path: string): void;
189
+ }
190
+ declare function keyPress(keyCode: number, repeat?: number): Promise<boolean>;
191
+ export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, KeyboardListener, OpenCV };