node-native-win-utils 1.3.2 → 1.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +20 -20
- package/README.md +755 -350
- package/binding.gyp +46 -46
- package/dist/index.d.ts +178 -173
- package/dist/index.js +163 -143
- package/dist/keyCodes.d.ts +101 -2
- package/dist/keyCodes.js +204 -102
- package/include/opencv2/opencv_modules.hpp +17 -17
- package/package.json +8 -6
- package/prebuilds/win32-x64/{node.napi.node → node-native-win-utils.node} +0 -0
- package/src/cpp/capturewindow.cpp +173 -173
- package/src/cpp/getWindowData.cpp +45 -45
- package/src/cpp/helpers.cpp +14 -14
- package/src/cpp/helpers.h +8 -8
- package/src/cpp/keyboard.cpp +238 -204
- package/src/cpp/main.cpp +30 -29
- package/src/cpp/mouse.cpp +175 -175
- package/src/cpp/opencv.cpp +425 -425
package/README.md
CHANGED
|
@@ -1,350 +1,755 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
##
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
The `
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
```
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
//
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
//
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
1
|
+
|
|
2
|
+
[![License][license-src]][license-href]
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
#### USDT TRC20 - TYAJ3K3MZraJhWimxxeCKcJ2SYABkVsrzi
|
|
6
|
+
#### USDT TON - UQDokuYZXr4OHvfslDqUoFYcp1_F8tcjQPk_TvqSSDk7SIa7
|
|
7
|
+
#### BTC - 1A3mNKFdWKXZ7Bcnez8LbWbYHgck1g4GeV
|
|
8
|
+
#### NOT - UQDokuYZXr4OHvfslDqUoFYcp1_F8tcjQPk_TvqSSDk7SIa7
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
#### Will be very thankful for any support
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
# Node Native Win Utils
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
I did it for myself because I didn't feel like dealing with libraries like 'node-ffi' to implement this functionality. Maybe someone will find it useful. It's WINDOWS OS ONLY
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
This package is a native addon for Node.js that allows you to perform various utility operations on Windows systems. It includes key event listeners, window data retrieval, window screenshot capture functionality, mouse movement, mouse click, mouse drag, and typing functionality, also I included precompiled libs of OpenCV(core, imgcodecs, imgproc)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# VESRION 1.3.3
|
|
29
|
+
|
|
30
|
+
Added a new function to simulate button press and release (`keyPress`), introduced an enumeration `KeyCodesHelper` with the most common key codes, and fixed a bug where the `typeString` function was not working with languages other than English.
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
# Installation
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
You can install the package using npm:
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
```shell
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
npm install node-native-win-utils
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# Usage
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## Importing the Package
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
To use the package, import the necessary functions, types, and classes:
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
```javascript
|
|
67
|
+
|
|
68
|
+
import {
|
|
69
|
+
|
|
70
|
+
keyDownHandler,
|
|
71
|
+
|
|
72
|
+
keyUpHandler,
|
|
73
|
+
|
|
74
|
+
getWindowData,
|
|
75
|
+
|
|
76
|
+
captureWindow,
|
|
77
|
+
|
|
78
|
+
captureWindowN,
|
|
79
|
+
|
|
80
|
+
mouseMove,
|
|
81
|
+
|
|
82
|
+
mouseClick,
|
|
83
|
+
|
|
84
|
+
mouseDrag,
|
|
85
|
+
|
|
86
|
+
typeString,
|
|
87
|
+
|
|
88
|
+
OpenCV,
|
|
89
|
+
|
|
90
|
+
} from "node-native-win-utils";
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Key Event Listeners
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
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:
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
```javascript
|
|
105
|
+
|
|
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
|
+
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Key Press
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
The keyPress function allows you to simulate a key press event. Provide the keyCode as a parameter and optionally the number of times to press the key:
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
```javascript
|
|
139
|
+
|
|
140
|
+
keyPress(65); // Press 'A' key once
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
keyPress(65, 3); // Press 'A' key three times
|
|
145
|
+
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## Key Code Helper
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
The KeyCodeHelper enum provides a set of key codes that can be used with key event functions:
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
```javascript
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
import { KeyCodeHelper } from "node-native-win-utils";
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
console.log(KeyCodeHelper.A); // Outputs the key code for 'A'
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
## Window Data
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
The `getWindowData` function retrieves information about a specific window identified by its name. It returns an object with properties `width`, `height`, `x`, and `y`, representing the window dimensions and position:
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
```javascript
|
|
179
|
+
|
|
180
|
+
const windowData = getWindowData("Window Name");
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
console.log("Window data:", windowData);
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
// Window data: { width: 800, height: 600, x: 50, y: 50 }
|
|
189
|
+
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
## Window Capture
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
The `captureWindow` function allows you to capture a screenshot of a specific window identified by its name. Provide the window name and the output path as parameters:
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
```javascript
|
|
203
|
+
|
|
204
|
+
captureWindow("Window Name", "output.png");
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
// Output: output.png with a screenshot of the window
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
## Mouse Movement
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
The `mouseMove` function allows you to move the mouse to a specific position on the screen. Provide the `posX` and `posY` coordinates as parameters:
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
```javascript
|
|
223
|
+
|
|
224
|
+
mouseMove(100, 200);
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
## Mouse Click
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
The `mouseClick` function allows you to perform a mouse click event. Optionally, you can specify the mouse button as a parameter (`"left"`, `"middle"`, or `"right"`). If no button is specified, a left mouse click is performed by default:
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
```javascript
|
|
239
|
+
|
|
240
|
+
mouseClick(); // Left mouse click
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
mouseClick("right"); // Right mouse click
|
|
245
|
+
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
## Mouse Drag
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
The `mouseDrag` function allows you to simulate dragging the mouse from one position to another. Provide the starting and ending coordinates (`startX`, `startY`, `endX`, `endY`) as parameters. Optionally, you can specify the speed at which the mouse should be dragged:
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
```javascript
|
|
259
|
+
|
|
260
|
+
mouseDrag(100, 200, 300, 400);
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
mouseDrag(100, 200, 300, 400, 100); // Drag with speed 100
|
|
265
|
+
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
## Typing
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
The `typeString` function allows you to simulate typing a string of characters. Provide the string to type as the `stringToType` parameter. Optionally, you can specify
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
a delay between each character (in milliseconds) using the `delay` parameter:
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
|
|
284
|
+
typeString("Hello, world!");
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
typeString("Hello, world!", 100); // Type with a delay of 100ms between characters
|
|
289
|
+
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
## Key Listener Class
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
The `KeyListener` class extends the EventEmitter class and simplifies working with the `keyDownHandler` and `keyUpHandler` functions. You can register event listeners for the "keyDown" and "keyUp" events using the `on` method:
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
```javascript
|
|
303
|
+
|
|
304
|
+
const listener = new KeyListener();
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
listener.on("keyDown", (data) => {
|
|
309
|
+
|
|
310
|
+
console.log("Key down:", data.keyCode, data.keyName);
|
|
311
|
+
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
// Key down: 8 Backspace
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
listener.on("keyUp", (data) => {
|
|
321
|
+
|
|
322
|
+
console.log("Key up:", data.keyCode, data.keyName);
|
|
323
|
+
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
// Key up: 8 Backspace
|
|
329
|
+
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
## OpenCV
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
The `OpenCV` class extends the capabilities of the native addon package by providing various image processing functionalities. It allows users to perform operations such as matching templates, blurring images, converting color formats, drawing rectangles, getting image regions, and writing images to files.
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
#### Constructor
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
```typescript
|
|
347
|
+
|
|
348
|
+
const image = new OpenCV(image: string | ImageData)
|
|
349
|
+
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
Creates a new instance of the `OpenCV` class with the specified image data. The `image` parameter can be either a file path (string) or an existing `ImageData` object.
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
#### Properties
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
##### `imageData: ImageData`
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
Holds the underlying image data that will be used for image processing operations.
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
##### `width: number`
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
Read-only property that returns the width of the image in pixels.
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
##### `height: number`
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
Read-only property that returns the height of the image in pixels.
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
#### Methods
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
##### `matchTemplate(template: ImageData, method?: number | null, mask?: ImageData): OpenCV`
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
Matches a template image with the current image and returns a new `OpenCV` instance containing the result.
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
- `template: ImageData`: The template image data to be matched.
|
|
399
|
+
|
|
400
|
+
- `method?: number | null`: (Optional) The matching method to be used. If not provided, the default method will be used.(currently no implemented)
|
|
401
|
+
|
|
402
|
+
- `mask?: ImageData`: (Optional) An optional mask image data to be used during the matching process.
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
##### `blur(sizeX: number, sizeY: number): OpenCV`
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
Applies a blur filter to the current image and returns a new `OpenCV` instance containing the blurred result.
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
- `sizeX: number`: The size of the blur kernel in the X direction.
|
|
415
|
+
|
|
416
|
+
- `sizeY: number`: The size of the blur kernel in the Y direction.
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
##### `bgrToGray(): OpenCV`
|
|
421
|
+
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
Converts the current image from the BGR color format to grayscale and returns a new `OpenCV` instance containing the grayscale result.
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
|
|
428
|
+
##### `drawRectangle(start: Point, end: Point, rgb: Color, thickness: number): OpenCV`
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
Draws a rectangle on the current image and returns a new `OpenCV` instance containing the modified result.
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
- `start: Point`: The starting point (top-left) of the rectangle.
|
|
437
|
+
|
|
438
|
+
- `end: Point`: The ending point (bottom-right) of the rectangle.
|
|
439
|
+
|
|
440
|
+
- `rgb: Color`: The color of the rectangle in the RGB format (e.g., `{ r: 255, g: 0, b: 0 }` for red).
|
|
441
|
+
|
|
442
|
+
- `thickness: number`: The thickness of the rectangle's border.
|
|
443
|
+
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
##### `getRegion(region: ROI): OpenCV`
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
Extracts a region of interest (ROI) from the current image and returns a new `OpenCV` instance containing the extracted region.
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
- `region: ROI`: An object specifying the region of interest with properties `x`, `y`, `width`, `height`.
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
|
|
458
|
+
##### `imwrite(path: string): void`
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
Writes the current image to a file specified by the `path`.
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
|
|
466
|
+
- `path: string`: The file path where the image will be saved.
|
|
467
|
+
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
## Functions
|
|
471
|
+
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
| Function | Parameters | Return Type |
|
|
475
|
+
|-----------------|----------------------------------------------------------------------------------------------|-------------|
|
|
476
|
+
| keyDownHandler | `callback: (keyCode: number) => void` | `void` |
|
|
477
|
+
| keyUpHandler | `callback: (keyCode: number) => void` | `void` |
|
|
478
|
+
| getWindowData | `windowName: string` | `WindowData`|
|
|
479
|
+
| captureWindow | `windowName: string, outputPath: string` | `void` |
|
|
480
|
+
| mouseMove | `posX: number, posY: number` | `boolean` |
|
|
481
|
+
| mouseClick | `button?: "left" \| "middle" \| "right"` | `boolean` |
|
|
482
|
+
| mouseDrag | `startX: number, startY: number, endX: number, endY: number, speed?: number` | `boolean` |
|
|
483
|
+
| typeString | `stringToType: string, delay?: number` | `boolean` |
|
|
484
|
+
| captureWindowN | `windowName: string` | `Buffer` |
|
|
485
|
+
| keyPress | `keyCode: number, repeat?: number` | `boolean` |
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
|
|
490
|
+
## Examples
|
|
491
|
+
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
Here are some examples of using the package:
|
|
495
|
+
|
|
496
|
+
|
|
497
|
+
|
|
498
|
+
```javascript
|
|
499
|
+
|
|
500
|
+
// Example usage of the OpenCV class
|
|
501
|
+
|
|
502
|
+
import { OpenCV } from "node-native-win-utils";
|
|
503
|
+
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
const image = new OpenCV("path/to/image.png");
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
|
|
510
|
+
const template = new OpenCV("path/to/template.png");
|
|
511
|
+
|
|
512
|
+
const matchedImage = image.matchTemplate(template.imageData);
|
|
513
|
+
|
|
514
|
+
|
|
515
|
+
|
|
516
|
+
const blurredImage = image.blur(5, 5);
|
|
517
|
+
|
|
518
|
+
|
|
519
|
+
|
|
520
|
+
const grayscaleImage = image.bgrToGray();
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
const regionOfInterest = { x: 100, y: 100, width: 200, height: 150 };
|
|
525
|
+
|
|
526
|
+
const regionImage = image.getRegion(regionOfInterest);
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
const redColor = { r: 255, g: 0, b: 0 };
|
|
531
|
+
|
|
532
|
+
const thickRectangle = image.drawRectangle(
|
|
533
|
+
|
|
534
|
+
{ x: 50, y: 50 },
|
|
535
|
+
|
|
536
|
+
{ x: 150, y: 150 },
|
|
537
|
+
|
|
538
|
+
redColor,
|
|
539
|
+
|
|
540
|
+
3
|
|
541
|
+
|
|
542
|
+
);
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
|
|
546
|
+
matchedImage.imwrite("output/matched.png");
|
|
547
|
+
|
|
548
|
+
blurredImage.imwrite("output/blurred.png");
|
|
549
|
+
|
|
550
|
+
grayscaleImage.imwrite("output/grayscale.png");
|
|
551
|
+
|
|
552
|
+
regionImage.imwrite("output/region.png");
|
|
553
|
+
|
|
554
|
+
thickRectangle.imwrite("output/thick_rectangle.png");
|
|
555
|
+
|
|
556
|
+
```
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
```javascript
|
|
561
|
+
|
|
562
|
+
// If you want to aply blur and convert to gray then do it that order:
|
|
563
|
+
|
|
564
|
+
image.blur(5, 5).bgrToGray();
|
|
565
|
+
|
|
566
|
+
// Otherwise you will get an error.
|
|
567
|
+
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
|
|
571
|
+
|
|
572
|
+
Please note that the above example demonstrates the usage of different methods available in the `OpenCV` class. Make sure to replace `"path/to/image.png"` and `"path/to/template.png"` with actual image file paths.
|
|
573
|
+
|
|
574
|
+
|
|
575
|
+
|
|
576
|
+
```javascript
|
|
577
|
+
|
|
578
|
+
import {
|
|
579
|
+
|
|
580
|
+
keyDownHandler,
|
|
581
|
+
|
|
582
|
+
keyUpHandler,
|
|
583
|
+
|
|
584
|
+
getWindowData,
|
|
585
|
+
|
|
586
|
+
captureWindow,
|
|
587
|
+
|
|
588
|
+
mouseMove,
|
|
589
|
+
|
|
590
|
+
mouseClick,
|
|
591
|
+
|
|
592
|
+
mouseDrag,
|
|
593
|
+
|
|
594
|
+
typeString,
|
|
595
|
+
|
|
596
|
+
KeyListener,
|
|
597
|
+
|
|
598
|
+
} from "node-native-win-utils";
|
|
599
|
+
|
|
600
|
+
|
|
601
|
+
|
|
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
|
+
// Retrieve window data
|
|
631
|
+
|
|
632
|
+
|
|
633
|
+
|
|
634
|
+
const windowData = getWindowData("My Window");
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
|
|
638
|
+
console.log("Window data:", windowData);
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
|
|
642
|
+
// Window data: { width: 1024, height: 768, x: 100, y: 100 }
|
|
643
|
+
|
|
644
|
+
|
|
645
|
+
|
|
646
|
+
// Capture window screenshot
|
|
647
|
+
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
captureWindow("My Window", "output.png");
|
|
651
|
+
|
|
652
|
+
|
|
653
|
+
|
|
654
|
+
// Output: output.png with a screenshot of the window
|
|
655
|
+
|
|
656
|
+
|
|
657
|
+
|
|
658
|
+
// Move the mouse
|
|
659
|
+
|
|
660
|
+
|
|
661
|
+
|
|
662
|
+
mouseMove(100, 200);
|
|
663
|
+
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
// Perform mouse click
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
|
|
670
|
+
mouseClick(); // Left mouse click
|
|
671
|
+
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
mouseClick("right"); // Right mouse click
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
|
|
678
|
+
// Simulate mouse drag
|
|
679
|
+
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
mouseDrag(100, 200, 300, 400);
|
|
683
|
+
|
|
684
|
+
|
|
685
|
+
|
|
686
|
+
mouseDrag(100, 200, 300, 400, 100); // Drag with speed 100
|
|
687
|
+
|
|
688
|
+
|
|
689
|
+
|
|
690
|
+
// Simulate typing
|
|
691
|
+
|
|
692
|
+
|
|
693
|
+
|
|
694
|
+
typeString("Hello, world!");
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
|
|
698
|
+
typeString("Hello, world!", 100); // Type with a delay of 100ms between characters
|
|
699
|
+
|
|
700
|
+
|
|
701
|
+
|
|
702
|
+
// Use KeyListener class
|
|
703
|
+
|
|
704
|
+
|
|
705
|
+
|
|
706
|
+
const listener = new KeyListener();
|
|
707
|
+
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
listener.on("keyDown", (data) => {
|
|
711
|
+
|
|
712
|
+
console.log("Key down:", data.keyCode, data.keyName);
|
|
713
|
+
|
|
714
|
+
});
|
|
715
|
+
|
|
716
|
+
|
|
717
|
+
|
|
718
|
+
// Key down: keyCode keyName
|
|
719
|
+
|
|
720
|
+
|
|
721
|
+
|
|
722
|
+
listener.on("keyUp", (data) => {
|
|
723
|
+
|
|
724
|
+
console.log("Key up:", data.keyCode, data.keyName);
|
|
725
|
+
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
|
|
729
|
+
|
|
730
|
+
// Key up: keyCode keyName
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
|
|
734
|
+
|
|
735
|
+
```
|
|
736
|
+
|
|
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
|
+
[OpenCV License](https://github.com/opencv/opencv/blob/master/LICENSE)
|
|
750
|
+
[MIT License](https://github.com/T-Rumibul/node-native-win-utils/blob/main/LICENSE)
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
[license-src]: https://img.shields.io/github/license/nuxt-modules/icon.svg?style=for-the-badge&colorA=18181B&colorB=28CF8D
|
|
754
|
+
|
|
755
|
+
[license-href]: https://github.com/T-Rumibul/node-native-win-utils/blob/main/LICENSE
|