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/dist/index.js CHANGED
@@ -1,143 +1,163 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.captureWindow = exports.getWindowData = exports.keyUpHandler = exports.keyDownHandler = exports.OpenCV = exports.KeyListener = void 0;
7
- const EventEmitter = require("events");
8
- const path_1 = __importDefault(require("path"));
9
- const fs_1 = __importDefault(require("fs"));
10
- const bindings = require("node-gyp-build")(path_1.default.resolve(__dirname, ".."));
11
- const keyCodes_1 = __importDefault(require("./keyCodes"));
12
- const { keyDownHandler, keyUpHandler, getWindowData, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, } = bindings;
13
- exports.keyDownHandler = keyDownHandler;
14
- exports.keyUpHandler = keyUpHandler;
15
- exports.getWindowData = getWindowData;
16
- exports.captureWindowN = captureWindowN;
17
- exports.mouseMove = mouseMove;
18
- exports.mouseClick = mouseClick;
19
- exports.mouseDrag = mouseDrag;
20
- exports.typeString = typeString;
21
- /**
22
- * Captures a window and saves it to a file.
23
- * @param windowName - The name of the window to capture.
24
- * @param path - The file path to save the captured image.
25
- * @returns True if the capture and save operation is successful, otherwise false.
26
- */
27
- function captureWindow(windowName, path) {
28
- const buffer = captureWindowN(windowName);
29
- if (!buffer)
30
- return false;
31
- fs_1.default.writeFileSync(path, buffer);
32
- return true;
33
- }
34
- exports.captureWindow = captureWindow;
35
- /**
36
- * Represents a class to listen to keyboard events.
37
- * @extends EventEmitter
38
- */
39
- class KeyListener extends EventEmitter {
40
- constructor() {
41
- super();
42
- keyDownHandler((keyCode) => {
43
- const keyName = keyCodes_1.default.get(keyCode.toString());
44
- this.emit("keyDown", {
45
- keyCode,
46
- keyName,
47
- });
48
- });
49
- keyUpHandler((keyCode) => {
50
- const keyName = keyCodes_1.default.get(keyCode.toString());
51
- this.emit("keyUp", {
52
- keyCode,
53
- keyName,
54
- });
55
- });
56
- }
57
- }
58
- exports.KeyListener = KeyListener;
59
- /**
60
- * Represents the OpenCV class that provides image processing functionality.
61
- */
62
- class OpenCV {
63
- imageData;
64
- /**
65
- * Represents the OpenCV class that provides image processing functionality.
66
- */
67
- constructor(image) {
68
- if (typeof image === "string") {
69
- this.imageData = imread(image);
70
- }
71
- else {
72
- this.imageData = image;
73
- }
74
- }
75
- /**
76
- * The width of the image.
77
- */
78
- get width() {
79
- return this.imageData.width;
80
- }
81
- /**
82
- * The height of the image.
83
- */
84
- get height() {
85
- return this.imageData.height;
86
- }
87
- /**
88
- * Matches a template image within the current image.
89
- * @param template - The template image data to search for.
90
- * @param method - The template matching method (optional).
91
- * @param mask - The optional mask image data to apply the operation (optional).
92
- * @returns The result of the template matching operation.
93
- */
94
- matchTemplate(template, method, mask) {
95
- return matchTemplate(this.imageData, template, method, mask);
96
- }
97
- /**
98
- * Applies a blur filter to the image.
99
- * @param sizeX - The horizontal size of the blur filter.
100
- * @param sizeY - The vertical size of the blur filter.
101
- * @returns A new OpenCV instance with the blurred image data.
102
- */
103
- blur(sizeX, sizeY) {
104
- return new OpenCV(blur(this.imageData, sizeX, sizeY));
105
- }
106
- /**
107
- * Converts the image from BGR to grayscale.
108
- * @returns A new OpenCV instance with the grayscale image data.
109
- */
110
- bgrToGray() {
111
- return new OpenCV(bgrToGray(this.imageData));
112
- }
113
- /**
114
- * Draws a rectangle on the image.
115
- * @param start - The starting point of the rectangle.
116
- * @param end - The ending point of the rectangle.
117
- * @param rgb - The color (RGB) of the rectangle.
118
- * @param thickness - The thickness of the rectangle's border.
119
- * @returns A new OpenCV instance with the image containing the drawn rectangle.
120
- */
121
- drawRectangle(start, end, rgb, thickness) {
122
- return new OpenCV(drawRectangle(this.imageData, start, end, rgb, thickness));
123
- }
124
- /**
125
- * Extracts a region of interest (ROI) from the image.
126
- * @param region - The region of interest defined as [x, y, width, height].
127
- * @returns A new OpenCV instance with the extracted region of interest.
128
- */
129
- getRegion(region) {
130
- return new OpenCV(getRegion(this.imageData, region));
131
- }
132
- /**
133
- * Writes the image data to a file.
134
- * @param path - The file path to save the image.
135
- */
136
- imwrite(path) {
137
- const buffer = imwrite(this.imageData);
138
- if (!buffer)
139
- return;
140
- fs_1.default.writeFileSync(path, buffer);
141
- }
142
- }
143
- exports.OpenCV = OpenCV;
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ 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;
7
+ exports.captureWindow = captureWindow;
8
+ exports.keyPress = keyPress;
9
+ const EventEmitter = require("events");
10
+ const path_1 = __importDefault(require("path"));
11
+ 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, } = bindings;
16
+ exports.keyDownHandler = keyDownHandler;
17
+ exports.keyUpHandler = keyUpHandler;
18
+ exports.getWindowData = getWindowData;
19
+ exports.captureWindowN = captureWindowN;
20
+ exports.mouseMove = mouseMove;
21
+ exports.mouseClick = mouseClick;
22
+ exports.mouseDrag = mouseDrag;
23
+ exports.typeString = typeString;
24
+ const rawPressKey = pressKey;
25
+ exports.rawPressKey = rawPressKey;
26
+ /**
27
+ * Captures a window and saves it to a file.
28
+ * @param windowName - The name of the window to capture.
29
+ * @param path - The file path to save the captured image.
30
+ * @returns True if the capture and save operation is successful, otherwise false.
31
+ */
32
+ function captureWindow(windowName, path) {
33
+ const buffer = captureWindowN(windowName);
34
+ if (!buffer)
35
+ return false;
36
+ fs_1.default.writeFileSync(path, buffer);
37
+ return true;
38
+ }
39
+ /**
40
+ * Represents a class to listen to keyboard events.
41
+ * @extends EventEmitter
42
+ */
43
+ class KeyListener extends EventEmitter {
44
+ constructor() {
45
+ super();
46
+ keyDownHandler((keyCode) => {
47
+ const keyName = keyCodes_1.keyCodes.get(keyCode.toString());
48
+ this.emit("keyDown", {
49
+ keyCode,
50
+ keyName,
51
+ });
52
+ });
53
+ keyUpHandler((keyCode) => {
54
+ const keyName = keyCodes_1.keyCodes.get(keyCode.toString());
55
+ this.emit("keyUp", {
56
+ keyCode,
57
+ keyName,
58
+ });
59
+ });
60
+ }
61
+ }
62
+ exports.KeyListener = KeyListener;
63
+ /**
64
+ * Represents the OpenCV class that provides image processing functionality.
65
+ */
66
+ class OpenCV {
67
+ imageData;
68
+ /**
69
+ * Represents the OpenCV class that provides image processing functionality.
70
+ */
71
+ constructor(image) {
72
+ if (typeof image === "string") {
73
+ this.imageData = imread(image);
74
+ }
75
+ else {
76
+ this.imageData = image;
77
+ }
78
+ }
79
+ /**
80
+ * The width of the image.
81
+ */
82
+ get width() {
83
+ return this.imageData.width;
84
+ }
85
+ /**
86
+ * The height of the image.
87
+ */
88
+ get height() {
89
+ return this.imageData.height;
90
+ }
91
+ /**
92
+ * Matches a template image within the current image.
93
+ * @param template - The template image data to search for.
94
+ * @param method - The template matching method (optional).
95
+ * @param mask - The optional mask image data to apply the operation (optional).
96
+ * @returns The result of the template matching operation.
97
+ */
98
+ matchTemplate(template, method, mask) {
99
+ return matchTemplate(this.imageData, template, method, mask);
100
+ }
101
+ /**
102
+ * Applies a blur filter to the image.
103
+ * @param sizeX - The horizontal size of the blur filter.
104
+ * @param sizeY - The vertical size of the blur filter.
105
+ * @returns A new OpenCV instance with the blurred image data.
106
+ */
107
+ blur(sizeX, sizeY) {
108
+ return new OpenCV(blur(this.imageData, sizeX, sizeY));
109
+ }
110
+ /**
111
+ * Converts the image from BGR to grayscale.
112
+ * @returns A new OpenCV instance with the grayscale image data.
113
+ */
114
+ bgrToGray() {
115
+ return new OpenCV(bgrToGray(this.imageData));
116
+ }
117
+ /**
118
+ * Draws a rectangle on the image.
119
+ * @param start - The starting point of the rectangle.
120
+ * @param end - The ending point of the rectangle.
121
+ * @param rgb - The color (RGB) of the rectangle.
122
+ * @param thickness - The thickness of the rectangle's border.
123
+ * @returns A new OpenCV instance with the image containing the drawn rectangle.
124
+ */
125
+ drawRectangle(start, end, rgb, thickness) {
126
+ return new OpenCV(drawRectangle(this.imageData, start, end, rgb, thickness));
127
+ }
128
+ /**
129
+ * Extracts a region of interest (ROI) from the image.
130
+ * @param region - The region of interest defined as [x, y, width, height].
131
+ * @returns A new OpenCV instance with the extracted region of interest.
132
+ */
133
+ getRegion(region) {
134
+ return new OpenCV(getRegion(this.imageData, region));
135
+ }
136
+ /**
137
+ * Writes the image data to a file.
138
+ * @param path - The file path to save the image.
139
+ */
140
+ imwrite(path) {
141
+ const buffer = imwrite(this.imageData);
142
+ if (!buffer)
143
+ return;
144
+ fs_1.default.writeFileSync(path, buffer);
145
+ }
146
+ }
147
+ exports.OpenCV = OpenCV;
148
+ function keyPress(keyCode, repeat) {
149
+ return new Promise((resolve, reject) => {
150
+ if (!repeat) {
151
+ let result = rawPressKey(keyCode);
152
+ if (!result)
153
+ reject('Something went wrong');
154
+ return resolve(true);
155
+ }
156
+ for (let i = 0; i < repeat; i++) {
157
+ let result = rawPressKey(keyCode);
158
+ if (!result)
159
+ reject('Something went wrong');
160
+ }
161
+ return resolve(true);
162
+ });
163
+ }
@@ -1,2 +1,101 @@
1
- declare const _default: Map<string, string>;
2
- export default _default;
1
+ export declare const keyCodes: Map<string, string>;
2
+ export declare enum KeyCodeHelper {
3
+ "Backspace" = 8,
4
+ "Tab" = 9,
5
+ "Enter" = 13,
6
+ "Shift" = 16,
7
+ "Ctrl" = 17,
8
+ "Alt" = 18,
9
+ "CapsLock" = 20,
10
+ "Escape" = 27,
11
+ "Space" = 32,
12
+ "PageUp" = 33,
13
+ "PageDown" = 34,
14
+ "End" = 35,
15
+ "Home" = 36,
16
+ "ArrowLeft" = 37,
17
+ "ArrowUp" = 38,
18
+ "ArrowRight" = 39,
19
+ "ArrowDown" = 40,
20
+ "Insert" = 45,
21
+ "Delete" = 46,
22
+ "Zero" = 48,
23
+ "One" = 49,
24
+ "Two" = 50,
25
+ "Three" = 51,
26
+ "Four" = 52,
27
+ "Five" = 53,
28
+ "Six" = 54,
29
+ "Seven" = 55,
30
+ "Eight" = 56,
31
+ "Nine" = 57,
32
+ "A" = 65,
33
+ "B" = 66,
34
+ "C" = 67,
35
+ "D" = 68,
36
+ "E" = 69,
37
+ "F" = 70,
38
+ "G" = 71,
39
+ "H" = 72,
40
+ "I" = 73,
41
+ "J" = 74,
42
+ "K" = 75,
43
+ "L" = 76,
44
+ "M" = 77,
45
+ "N" = 78,
46
+ "O" = 79,
47
+ "P" = 80,
48
+ "Q" = 81,
49
+ "R" = 82,
50
+ "S" = 83,
51
+ "T" = 84,
52
+ "U" = 85,
53
+ "V" = 86,
54
+ "W" = 87,
55
+ "X" = 88,
56
+ "Y" = 89,
57
+ "Z" = 90,
58
+ "MetaLeft" = 91,
59
+ "MetaRight" = 92,
60
+ "ContextMenu" = 93,
61
+ "Numpad0" = 96,
62
+ "Numpad1" = 97,
63
+ "Numpad2" = 98,
64
+ "Numpad3" = 99,
65
+ "Numpad4" = 100,
66
+ "Numpad5" = 101,
67
+ "Numpad6" = 102,
68
+ "Numpad7" = 103,
69
+ "Numpad8" = 104,
70
+ "Numpad9" = 105,
71
+ "NumpadMultiply" = 106,
72
+ "NumpadAdd" = 107,
73
+ "NumpadSubtract" = 109,
74
+ "NumpadDecimal" = 110,
75
+ "NumpadDivide" = 111,
76
+ "F1" = 112,
77
+ "F2" = 113,
78
+ "F3" = 114,
79
+ "F4" = 115,
80
+ "F5" = 116,
81
+ "F6" = 117,
82
+ "F7" = 118,
83
+ "F8" = 119,
84
+ "F9" = 120,
85
+ "F10" = 121,
86
+ "F11" = 122,
87
+ "F12" = 123,
88
+ "NumLock" = 144,
89
+ "ScrollLock" = 145,
90
+ "Semicolon" = 186,
91
+ "Equal" = 187,
92
+ "Comma" = 188,
93
+ "Minus" = 189,
94
+ "Period" = 190,
95
+ "Slash" = 191,
96
+ "Backquote" = 192,
97
+ "BracketLeft" = 219,
98
+ "Backslash" = 220,
99
+ "BracketRight" = 221,
100
+ "Quote" = 222
101
+ }