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.
- package/README.md +29 -82
- package/binding.gyp +2 -0
- package/dist/dirnameLocal.cjs +4 -0
- package/dist/dirnameLocal.d.cts +1 -0
- package/dist/dirnameLocal.d.mts +1 -0
- package/dist/dirnameLocal.mjs +2 -0
- package/dist/{index.js → index.cjs} +83 -16
- package/dist/{index.d.ts → index.d.cts} +68 -17
- package/dist/index.d.mts +230 -0
- package/dist/index.mjs +212 -0
- package/dist/keyCodes.d.mts +101 -0
- package/dist/keyCodes.mjs +201 -0
- package/node22.json +16 -0
- package/package.json +19 -9
- package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
- package/src/cpp/keyboard.cpp +141 -140
- package/src/cpp/main.cpp +9 -3
- package/src/cpp/{capturewindow.cpp → screenshot.cpp} +174 -2
- package/src/dirnameLocal.mts +3 -0
- package/src/index.mts +455 -0
- package/src/keyCodes.mts +203 -0
- package/dllCopy.js +0 -14
- package/include/opencv2/core/affine.hpp +0 -678
- package/include/opencv2/core/async.hpp +0 -105
- package/include/opencv2/core/base.hpp +0 -664
- package/include/opencv2/core/bindings_utils.hpp +0 -325
- package/include/opencv2/core/bufferpool.hpp +0 -40
- package/include/opencv2/core/check.hpp +0 -170
- package/include/opencv2/core/core.hpp +0 -48
- package/include/opencv2/core/core_c.h +0 -3128
- package/include/opencv2/core/cuda/block.hpp +0 -211
- package/include/opencv2/core/cuda/border_interpolate.hpp +0 -722
- package/include/opencv2/core/cuda/color.hpp +0 -309
- package/include/opencv2/core/cuda/common.hpp +0 -131
- package/include/opencv2/core/cuda/datamov_utils.hpp +0 -113
- package/include/opencv2/core/cuda/detail/color_detail.hpp +0 -2018
- package/include/opencv2/core/cuda/detail/reduce.hpp +0 -365
- package/include/opencv2/core/cuda/detail/reduce_key_val.hpp +0 -502
- package/include/opencv2/core/cuda/detail/transform_detail.hpp +0 -392
- package/include/opencv2/core/cuda/detail/type_traits_detail.hpp +0 -191
- package/include/opencv2/core/cuda/detail/vec_distance_detail.hpp +0 -121
- package/include/opencv2/core/cuda/dynamic_smem.hpp +0 -88
- package/include/opencv2/core/cuda/emulation.hpp +0 -269
- package/include/opencv2/core/cuda/filters.hpp +0 -293
- package/include/opencv2/core/cuda/funcattrib.hpp +0 -79
- package/include/opencv2/core/cuda/functional.hpp +0 -805
- package/include/opencv2/core/cuda/limits.hpp +0 -128
- package/include/opencv2/core/cuda/reduce.hpp +0 -209
- package/include/opencv2/core/cuda/saturate_cast.hpp +0 -292
- package/include/opencv2/core/cuda/scan.hpp +0 -258
- package/include/opencv2/core/cuda/simd_functions.hpp +0 -869
- package/include/opencv2/core/cuda/transform.hpp +0 -75
- package/include/opencv2/core/cuda/type_traits.hpp +0 -90
- package/include/opencv2/core/cuda/utility.hpp +0 -230
- package/include/opencv2/core/cuda/vec_distance.hpp +0 -232
- package/include/opencv2/core/cuda/vec_math.hpp +0 -923
- package/include/opencv2/core/cuda/vec_traits.hpp +0 -288
- package/include/opencv2/core/cuda/warp.hpp +0 -139
- package/include/opencv2/core/cuda/warp_reduce.hpp +0 -76
- package/include/opencv2/core/cuda/warp_shuffle.hpp +0 -162
- package/include/opencv2/core/cuda.hpp +0 -1279
- package/include/opencv2/core/cuda.inl.hpp +0 -763
- package/include/opencv2/core/cuda_stream_accessor.hpp +0 -86
- package/include/opencv2/core/cuda_types.hpp +0 -144
- package/include/opencv2/core/cv_cpu_dispatch.h +0 -381
- package/include/opencv2/core/cv_cpu_helper.h +0 -550
- package/include/opencv2/core/cvdef.h +0 -973
- package/include/opencv2/core/cvstd.hpp +0 -190
- package/include/opencv2/core/cvstd.inl.hpp +0 -197
- package/include/opencv2/core/cvstd_wrapper.hpp +0 -154
- package/include/opencv2/core/detail/async_promise.hpp +0 -71
- package/include/opencv2/core/detail/dispatch_helper.impl.hpp +0 -49
- package/include/opencv2/core/detail/exception_ptr.hpp +0 -27
- package/include/opencv2/core/directx.hpp +0 -184
- package/include/opencv2/core/dualquaternion.hpp +0 -979
- package/include/opencv2/core/dualquaternion.inl.hpp +0 -487
- package/include/opencv2/core/eigen.hpp +0 -402
- package/include/opencv2/core/fast_math.hpp +0 -433
- package/include/opencv2/core/hal/hal.hpp +0 -256
- package/include/opencv2/core/hal/interface.h +0 -190
- package/include/opencv2/core/hal/intrin.hpp +0 -939
- package/include/opencv2/core/hal/intrin_avx.hpp +0 -3177
- package/include/opencv2/core/hal/intrin_avx512.hpp +0 -3090
- package/include/opencv2/core/hal/intrin_cpp.hpp +0 -3321
- package/include/opencv2/core/hal/intrin_forward.hpp +0 -191
- package/include/opencv2/core/hal/intrin_lasx.hpp +0 -3236
- package/include/opencv2/core/hal/intrin_msa.hpp +0 -1887
- package/include/opencv2/core/hal/intrin_neon.hpp +0 -2610
- package/include/opencv2/core/hal/intrin_rvv.hpp +0 -3320
- package/include/opencv2/core/hal/intrin_rvv071.hpp +0 -2545
- package/include/opencv2/core/hal/intrin_rvv_scalable.hpp +0 -2080
- package/include/opencv2/core/hal/intrin_sse.hpp +0 -3467
- package/include/opencv2/core/hal/intrin_sse_em.hpp +0 -180
- package/include/opencv2/core/hal/intrin_vsx.hpp +0 -1608
- package/include/opencv2/core/hal/intrin_wasm.hpp +0 -2782
- package/include/opencv2/core/hal/msa_macros.h +0 -1558
- package/include/opencv2/core/hal/simd_utils.impl.hpp +0 -186
- package/include/opencv2/core/llapi/llapi.h +0 -102
- package/include/opencv2/core/mat.hpp +0 -3775
- package/include/opencv2/core/mat.inl.hpp +0 -3422
- package/include/opencv2/core/matx.hpp +0 -1536
- package/include/opencv2/core/neon_utils.hpp +0 -128
- package/include/opencv2/core/ocl.hpp +0 -917
- package/include/opencv2/core/ocl_genbase.hpp +0 -69
- package/include/opencv2/core/opencl/ocl_defs.hpp +0 -82
- package/include/opencv2/core/opencl/opencl_info.hpp +0 -212
- package/include/opencv2/core/opencl/opencl_svm.hpp +0 -81
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp +0 -602
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp +0 -146
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +0 -371
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp +0 -272
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +0 -62
- package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +0 -42
- package/include/opencv2/core/opencl/runtime/opencl_clblas.hpp +0 -53
- package/include/opencv2/core/opencl/runtime/opencl_clfft.hpp +0 -53
- package/include/opencv2/core/opencl/runtime/opencl_core.hpp +0 -84
- package/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp +0 -47
- package/include/opencv2/core/opencl/runtime/opencl_gl.hpp +0 -53
- package/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp +0 -47
- package/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp +0 -48
- package/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp +0 -42
- package/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp +0 -166
- package/include/opencv2/core/opengl.hpp +0 -733
- package/include/opencv2/core/openvx/ovx_defs.hpp +0 -48
- package/include/opencv2/core/operations.hpp +0 -610
- package/include/opencv2/core/optim.hpp +0 -302
- package/include/opencv2/core/ovx.hpp +0 -28
- package/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +0 -72
- package/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +0 -153
- package/include/opencv2/core/parallel/parallel_backend.hpp +0 -90
- package/include/opencv2/core/persistence.hpp +0 -1350
- package/include/opencv2/core/private/cv_cpu_include_simd_declarations.hpp +0 -30
- package/include/opencv2/core/private.cuda.hpp +0 -169
- package/include/opencv2/core/private.hpp +0 -896
- package/include/opencv2/core/quaternion.hpp +0 -1696
- package/include/opencv2/core/quaternion.inl.hpp +0 -1063
- package/include/opencv2/core/saturate.hpp +0 -180
- package/include/opencv2/core/simd_intrinsics.hpp +0 -87
- package/include/opencv2/core/softfloat.hpp +0 -514
- package/include/opencv2/core/sse_utils.hpp +0 -652
- package/include/opencv2/core/traits.hpp +0 -417
- package/include/opencv2/core/types.hpp +0 -2457
- package/include/opencv2/core/types_c.h +0 -2126
- package/include/opencv2/core/utility.hpp +0 -1229
- package/include/opencv2/core/utils/allocator_stats.hpp +0 -29
- package/include/opencv2/core/utils/allocator_stats.impl.hpp +0 -158
- package/include/opencv2/core/utils/buffer_area.private.hpp +0 -136
- package/include/opencv2/core/utils/configuration.private.hpp +0 -22
- package/include/opencv2/core/utils/filesystem.hpp +0 -82
- package/include/opencv2/core/utils/filesystem.private.hpp +0 -66
- package/include/opencv2/core/utils/fp_control.private.hpp +0 -29
- package/include/opencv2/core/utils/fp_control_utils.hpp +0 -69
- package/include/opencv2/core/utils/instrumentation.hpp +0 -125
- package/include/opencv2/core/utils/lock.private.hpp +0 -119
- package/include/opencv2/core/utils/logger.defines.hpp +0 -42
- package/include/opencv2/core/utils/logger.hpp +0 -218
- package/include/opencv2/core/utils/logtag.hpp +0 -28
- package/include/opencv2/core/utils/plugin_loader.private.hpp +0 -165
- package/include/opencv2/core/utils/tls.hpp +0 -235
- package/include/opencv2/core/utils/trace.hpp +0 -252
- package/include/opencv2/core/utils/trace.private.hpp +0 -421
- package/include/opencv2/core/va_intel.hpp +0 -75
- package/include/opencv2/core/version.hpp +0 -26
- package/include/opencv2/core/vsx_utils.hpp +0 -1047
- package/include/opencv2/core.hpp +0 -3365
- package/include/opencv2/imgcodecs/imgcodecs.hpp +0 -48
- package/include/opencv2/imgcodecs/imgcodecs_c.h +0 -1
- package/include/opencv2/imgcodecs/ios.h +0 -59
- package/include/opencv2/imgcodecs/legacy/constants_c.h +0 -54
- package/include/opencv2/imgcodecs/macosx.h +0 -20
- package/include/opencv2/imgcodecs.hpp +0 -407
- package/include/opencv2/imgproc/bindings.hpp +0 -34
- package/include/opencv2/imgproc/detail/gcgraph.hpp +0 -395
- package/include/opencv2/imgproc/hal/hal.hpp +0 -246
- package/include/opencv2/imgproc/hal/interface.h +0 -46
- package/include/opencv2/imgproc/imgproc.hpp +0 -48
- package/include/opencv2/imgproc/imgproc_c.h +0 -1177
- package/include/opencv2/imgproc/segmentation.hpp +0 -141
- package/include/opencv2/imgproc/types_c.h +0 -659
- package/include/opencv2/imgproc.hpp +0 -5035
- package/include/opencv2/opencv_modules.hpp +0 -17
- package/include/tesseract/baseapi.h +0 -820
- package/include/tesseract/capi.h +0 -485
- package/include/tesseract/export.h +0 -37
- package/include/tesseract/ltrresultiterator.h +0 -235
- package/include/tesseract/ocrclass.h +0 -158
- package/include/tesseract/osdetect.h +0 -139
- package/include/tesseract/pageiterator.h +0 -364
- package/include/tesseract/publictypes.h +0 -281
- package/include/tesseract/renderer.h +0 -334
- package/include/tesseract/resultiterator.h +0 -250
- package/include/tesseract/tesseract.h +0 -40
- package/include/tesseract/unichar.h +0 -174
- package/include/tesseract/version.h +0 -34
- package/include/tesseract/version.h.in +0 -34
- package/libs/libjpeg-turbo.lib +0 -0
- package/libs/libpng.lib +0 -0
- package/libs/opencv_core470.lib +0 -0
- package/libs/opencv_imgcodecs470.lib +0 -0
- package/libs/opencv_imgproc470.lib +0 -0
- package/libs/tesseract.lib +0 -0
- package/libs/zlib.lib +0 -0
- /package/dist/{keyCodes.js → keyCodes.cjs} +0 -0
- /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
|
-
|
|
71
|
-
|
|
72
|
-
keyUpHandler,
|
|
70
|
+
KeyboardListener
|
|
73
71
|
|
|
74
72
|
getWindowData,
|
|
75
73
|
|
|
@@ -93,38 +91,30 @@ OpenCV,
|
|
|
93
91
|
|
|
94
92
|
|
|
95
93
|
|
|
96
|
-
##
|
|
94
|
+
## Keyboard Event Listener
|
|
97
95
|
|
|
98
96
|
|
|
99
97
|
|
|
100
|
-
The package provides
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
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
|
-
|
|
|
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`
|
|
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`
|
|
485
|
-
| keyPress | `keyCode: number, repeat?: number`
|
|
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
|
|
661
|
+
// Use KeyboardListener class
|
|
703
662
|
|
|
704
663
|
|
|
705
664
|
|
|
706
|
-
const listener =
|
|
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 @@
|
|
|
1
|
+
export declare const __dirnameLocal: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const __dirnameLocal: string;
|
|
@@ -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.
|
|
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
|
-
|
|
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
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
*
|
|
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
|
|
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
|
-
|
|
48
|
-
|
|
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
|
-
|
|
55
|
-
|
|
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
|
-
|
|
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
|
|
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
|
|
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-
|
|
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
|
|
41
|
+
export type SetKeyCallback = (callback: (keyCode: number) => void) => void;
|
|
42
42
|
/**
|
|
43
|
-
* The handler to
|
|
44
|
-
* @param callback - The callback function to handle key-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
*
|
|
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 -
|
|
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
|
-
*
|
|
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 -
|
|
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
|
-
*
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
230
|
+
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, captureScreenAsync, KeyboardListener, OpenCV };
|