node-native-win-utils 1.3.2 → 1.3.3

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