node-native-win-utils 2.1.0 → 2.1.2
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 +1 -1
- package/dist/index.cjs +47 -4
- package/dist/index.d.cts +52 -7
- package/dist/index.d.mts +52 -7
- package/dist/index.mjs +46 -4
- package/package.json +1 -1
- package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
- package/src/cpp/main.cpp +1 -0
- package/src/cpp/opencv.cpp +46 -0
- package/src/index.mts +14 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
|
|
2
2
|
[![License][license-src]][license-href]
|
|
3
|
-

|
|
4
4
|
|
|
5
5
|
#### USDT TRC20 - TYAJ3K3MZraJhWimxxeCKcJ2SYABkVsrzi
|
|
6
6
|
#### USDT TON - UQDokuYZXr4OHvfslDqUoFYcp1_F8tcjQPk_TvqSSDk7SIa7
|
package/dist/index.cjs
CHANGED
|
@@ -3,7 +3,7 @@ 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.OpenCV = exports.KeyboardListener = exports.textRecognition = exports.KeyCodeHelper = exports.rawPressKey = exports.typeString = exports.mouseDrag = exports.mouseClick = exports.mouseMove = exports.captureWindowN = exports.getWindowData = void 0;
|
|
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;
|
|
@@ -17,9 +17,10 @@ const keyCodes_cjs_1 = require("./keyCodes.cjs");
|
|
|
17
17
|
Object.defineProperty(exports, "KeyCodeHelper", { enumerable: true, get: function () { return keyCodes_cjs_1.KeyCodeHelper; } });
|
|
18
18
|
const dirnameLocal_cjs_1 = require("./dirnameLocal.cjs");
|
|
19
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;
|
|
20
|
+
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition, equalizeHist } = bindings;
|
|
21
21
|
exports.getWindowData = getWindowData;
|
|
22
22
|
exports.captureWindowN = captureWindowN;
|
|
23
|
+
exports.captureScreenAsync = captureScreenAsync;
|
|
23
24
|
exports.mouseMove = mouseMove;
|
|
24
25
|
exports.mouseClick = mouseClick;
|
|
25
26
|
exports.mouseDrag = mouseDrag;
|
|
@@ -56,21 +57,36 @@ function captureScreenToFile(path) {
|
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
59
|
/**
|
|
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.
|
|
60
64
|
* @extends EventEmitter
|
|
61
65
|
*/
|
|
62
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
|
+
*/
|
|
63
73
|
constructor() {
|
|
64
74
|
super();
|
|
75
|
+
// Set the callback for key down events.
|
|
65
76
|
setKeyDownCallback((keyCode) => {
|
|
77
|
+
// Look up the human-readable key name from a mapping.
|
|
66
78
|
const keyName = keyCodes_cjs_1.keyCodes.get(keyCode.toString());
|
|
79
|
+
// Emit the 'keyDown' event to all registered JavaScript listeners.
|
|
67
80
|
this.emit("keyDown", {
|
|
68
81
|
keyCode,
|
|
69
82
|
keyName,
|
|
70
83
|
});
|
|
71
84
|
});
|
|
85
|
+
// Set the callback for key up events.
|
|
72
86
|
setKeyUpCallback((keyCode) => {
|
|
87
|
+
// Look up the human-readable key name from a mapping.
|
|
73
88
|
const keyName = keyCodes_cjs_1.keyCodes.get(keyCode.toString());
|
|
89
|
+
// Emit the 'keyUp' event to all registered JavaScript listeners.
|
|
74
90
|
this.emit("keyUp", {
|
|
75
91
|
keyCode,
|
|
76
92
|
keyName,
|
|
@@ -78,13 +94,33 @@ class KeyboardListenerPrivate extends events_1.default {
|
|
|
78
94
|
});
|
|
79
95
|
}
|
|
80
96
|
}
|
|
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
|
+
*/
|
|
81
103
|
class KeyboardListener {
|
|
104
|
+
/**
|
|
105
|
+
* Holds the singleton instance of KeyboardListenerPrivate.
|
|
106
|
+
*/
|
|
82
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
|
+
*/
|
|
83
113
|
static listener() {
|
|
84
|
-
if (!this.listenerInstance)
|
|
114
|
+
if (!this.listenerInstance) {
|
|
85
115
|
this.listenerInstance = new KeyboardListenerPrivate();
|
|
116
|
+
}
|
|
86
117
|
return this.listenerInstance;
|
|
87
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
|
+
*/
|
|
88
124
|
static destroy() {
|
|
89
125
|
this.listenerInstance = null;
|
|
90
126
|
unsetKeyDownCallback();
|
|
@@ -146,6 +182,13 @@ class OpenCV {
|
|
|
146
182
|
bgrToGray() {
|
|
147
183
|
return new OpenCV(bgrToGray(this.imageData));
|
|
148
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
187
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
188
|
+
*/
|
|
189
|
+
equalizeHist() {
|
|
190
|
+
return new OpenCV(equalizeHist(this.imageData));
|
|
191
|
+
}
|
|
149
192
|
/**
|
|
150
193
|
* Draws a rectangle on the image.
|
|
151
194
|
* @param start - The starting point of the rectangle.
|
package/dist/index.d.cts
CHANGED
|
@@ -78,11 +78,12 @@ export type Imwrite = (image: ImageData) => Buffer;
|
|
|
78
78
|
export type MatchTemplate = (image: ImageData, template: ImageData, method?: number | null, mask?: ImageData) => MatchData;
|
|
79
79
|
export type Blur = (image: ImageData, sizeX: number, sizeY: number) => ImageData;
|
|
80
80
|
export type BgrToGray = (image: ImageData) => ImageData;
|
|
81
|
+
export type EqualizeHist = (image: ImageData) => ImageData;
|
|
81
82
|
export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
|
|
82
83
|
export type GetRegion = (image: ImageData, region: ROI) => ImageData;
|
|
83
84
|
export type TextRecognition = (trainedDataPath: string, dataLang: string, imagePath: string) => string;
|
|
84
85
|
export type CaptureScreenAsync = () => Promise<Buffer>;
|
|
85
|
-
declare const getWindowData: GetWindowData, captureWindowN: CaptureWindow, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
|
|
86
|
+
declare const getWindowData: GetWindowData, captureWindowN: CaptureWindow, captureScreenAsync: CaptureScreenAsync, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
|
|
86
87
|
declare const rawPressKey: PressKey;
|
|
87
88
|
/**
|
|
88
89
|
* Captures a window and saves it to a file.
|
|
@@ -97,20 +98,31 @@ declare function captureWindow(windowName: string, path: string): boolean;
|
|
|
97
98
|
* @returns True if the capture and save operation is successful, otherwise false.
|
|
98
99
|
*/
|
|
99
100
|
declare function captureScreenToFile(path: string): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Interface representing a private keyboard listener that extends EventEmitter.
|
|
103
|
+
* It declares event handlers for native keyboard events, which are forwarded from
|
|
104
|
+
* the C++ bindings using thread-safe callbacks.
|
|
105
|
+
*/
|
|
100
106
|
interface KeyboardListenerPrivate extends EventEmitter {
|
|
101
107
|
/**
|
|
102
|
-
*
|
|
108
|
+
* Registers an event handler for the 'keyDown' event.
|
|
109
|
+
* This event is fired when a key is pressed down. The C++ native binding calls
|
|
110
|
+
* this callback using a thread-safe mechanism (via Napi::ThreadSafeFunction).
|
|
103
111
|
* @param event - The event name ('keyDown').
|
|
104
|
-
* @param callback -
|
|
112
|
+
* @param callback - Function invoked with an object containing the keyCode and keyName.
|
|
113
|
+
* @returns The current instance for method chaining.
|
|
105
114
|
*/
|
|
106
115
|
on(event: "keyDown", callback: (data: {
|
|
107
116
|
keyCode: number;
|
|
108
117
|
keyName: string;
|
|
109
118
|
}) => void): this;
|
|
110
119
|
/**
|
|
111
|
-
*
|
|
120
|
+
* Registers an event handler for the 'keyUp' event.
|
|
121
|
+
* This event is fired when a key is released. The underlying C++ code safely
|
|
122
|
+
* invokes this callback from a background thread using a thread-safe function.
|
|
112
123
|
* @param event - The event name ('keyUp').
|
|
113
|
-
* @param callback -
|
|
124
|
+
* @param callback - Function invoked with an object containing the keyCode and keyName.
|
|
125
|
+
* @returns The current instance for method chaining.
|
|
114
126
|
*/
|
|
115
127
|
on(event: "keyUp", callback: (data: {
|
|
116
128
|
keyCode: number;
|
|
@@ -118,15 +130,43 @@ interface KeyboardListenerPrivate extends EventEmitter {
|
|
|
118
130
|
}) => void): this;
|
|
119
131
|
}
|
|
120
132
|
/**
|
|
121
|
-
*
|
|
133
|
+
* Class that implements a private keyboard listener.
|
|
134
|
+
* This class leverages native C++ bindings to hook into system keyboard events.
|
|
135
|
+
* The C++ layer uses global ThreadSafeFunction objects to safely dispatch events
|
|
136
|
+
* (using a dedicated monitoring thread, mutexes, and atomic flags) to JavaScript.
|
|
122
137
|
* @extends EventEmitter
|
|
123
138
|
*/
|
|
124
139
|
declare class KeyboardListenerPrivate extends EventEmitter {
|
|
140
|
+
/**
|
|
141
|
+
* Constructs the keyboard listener and sets up native callbacks.
|
|
142
|
+
* The callbacks (set via setKeyDownCallback and setKeyUpCallback) are defined in the
|
|
143
|
+
* C++ binding layer. They are responsible for invoking these JavaScript callbacks
|
|
144
|
+
* in a thread-safe manner once a key event is detected.
|
|
145
|
+
*/
|
|
125
146
|
constructor();
|
|
126
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* A singleton manager for the KeyboardListenerPrivate instance.
|
|
150
|
+
* This class ensures that only one native keyboard listener is active at any time.
|
|
151
|
+
* When the listener is destroyed, it calls unsetKeyDownCallback and unsetKeyUpCallback
|
|
152
|
+
* to clean up native resources, mirroring the cleanup logic in the C++ bindings.
|
|
153
|
+
*/
|
|
127
154
|
declare class KeyboardListener {
|
|
155
|
+
/**
|
|
156
|
+
* Holds the singleton instance of KeyboardListenerPrivate.
|
|
157
|
+
*/
|
|
128
158
|
private static listenerInstance;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the singleton instance of KeyboardListenerPrivate. If not already created,
|
|
161
|
+
* it instantiates a new instance and sets up the native callbacks.
|
|
162
|
+
* @returns The active KeyboardListenerPrivate instance.
|
|
163
|
+
*/
|
|
129
164
|
static listener(): KeyboardListenerPrivate;
|
|
165
|
+
/**
|
|
166
|
+
* Destroys the current KeyboardListenerPrivate instance and cleans up native callbacks.
|
|
167
|
+
* This method calls unsetKeyDownCallback and unsetKeyUpCallback to release any
|
|
168
|
+
* native resources (such as the global ThreadSafeFunctions) and stops the monitoring thread.
|
|
169
|
+
*/
|
|
130
170
|
static destroy(): void;
|
|
131
171
|
}
|
|
132
172
|
/**
|
|
@@ -166,6 +206,11 @@ declare class OpenCV {
|
|
|
166
206
|
* @returns A new OpenCV instance with the grayscale image data.
|
|
167
207
|
*/
|
|
168
208
|
bgrToGray(): OpenCV;
|
|
209
|
+
/**
|
|
210
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
211
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
212
|
+
*/
|
|
213
|
+
equalizeHist(): OpenCV;
|
|
169
214
|
/**
|
|
170
215
|
* Draws a rectangle on the image.
|
|
171
216
|
* @param start - The starting point of the rectangle.
|
|
@@ -188,4 +233,4 @@ declare class OpenCV {
|
|
|
188
233
|
imwrite(path: string): void;
|
|
189
234
|
}
|
|
190
235
|
declare function keyPress(keyCode: number, repeat?: number): Promise<boolean>;
|
|
191
|
-
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, KeyboardListener, OpenCV };
|
|
236
|
+
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, captureScreenAsync, KeyboardListener, OpenCV };
|
package/dist/index.d.mts
CHANGED
|
@@ -78,11 +78,12 @@ export type Imwrite = (image: ImageData) => Buffer;
|
|
|
78
78
|
export type MatchTemplate = (image: ImageData, template: ImageData, method?: number | null, mask?: ImageData) => MatchData;
|
|
79
79
|
export type Blur = (image: ImageData, sizeX: number, sizeY: number) => ImageData;
|
|
80
80
|
export type BgrToGray = (image: ImageData) => ImageData;
|
|
81
|
+
export type EqualizeHist = (image: ImageData) => ImageData;
|
|
81
82
|
export type DrawRectangle = (image: ImageData, start: Point, end: Point, rgb: Color, thickness: number) => ImageData;
|
|
82
83
|
export type GetRegion = (image: ImageData, region: ROI) => ImageData;
|
|
83
84
|
export type TextRecognition = (trainedDataPath: string, dataLang: string, imagePath: string) => string;
|
|
84
85
|
export type CaptureScreenAsync = () => Promise<Buffer>;
|
|
85
|
-
declare const getWindowData: GetWindowData, captureWindowN: CaptureWindow, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
|
|
86
|
+
declare const getWindowData: GetWindowData, captureWindowN: CaptureWindow, captureScreenAsync: CaptureScreenAsync, mouseMove: MouseMove, mouseClick: MouseClick, mouseDrag: MouseDrag, typeString: TypeString, textRecognition: TextRecognition;
|
|
86
87
|
declare const rawPressKey: PressKey;
|
|
87
88
|
/**
|
|
88
89
|
* Captures a window and saves it to a file.
|
|
@@ -97,20 +98,31 @@ declare function captureWindow(windowName: string, path: string): boolean;
|
|
|
97
98
|
* @returns True if the capture and save operation is successful, otherwise false.
|
|
98
99
|
*/
|
|
99
100
|
declare function captureScreenToFile(path: string): Promise<boolean>;
|
|
101
|
+
/**
|
|
102
|
+
* Interface representing a private keyboard listener that extends EventEmitter.
|
|
103
|
+
* It declares event handlers for native keyboard events, which are forwarded from
|
|
104
|
+
* the C++ bindings using thread-safe callbacks.
|
|
105
|
+
*/
|
|
100
106
|
interface KeyboardListenerPrivate extends EventEmitter {
|
|
101
107
|
/**
|
|
102
|
-
*
|
|
108
|
+
* Registers an event handler for the 'keyDown' event.
|
|
109
|
+
* This event is fired when a key is pressed down. The C++ native binding calls
|
|
110
|
+
* this callback using a thread-safe mechanism (via Napi::ThreadSafeFunction).
|
|
103
111
|
* @param event - The event name ('keyDown').
|
|
104
|
-
* @param callback -
|
|
112
|
+
* @param callback - Function invoked with an object containing the keyCode and keyName.
|
|
113
|
+
* @returns The current instance for method chaining.
|
|
105
114
|
*/
|
|
106
115
|
on(event: "keyDown", callback: (data: {
|
|
107
116
|
keyCode: number;
|
|
108
117
|
keyName: string;
|
|
109
118
|
}) => void): this;
|
|
110
119
|
/**
|
|
111
|
-
*
|
|
120
|
+
* Registers an event handler for the 'keyUp' event.
|
|
121
|
+
* This event is fired when a key is released. The underlying C++ code safely
|
|
122
|
+
* invokes this callback from a background thread using a thread-safe function.
|
|
112
123
|
* @param event - The event name ('keyUp').
|
|
113
|
-
* @param callback -
|
|
124
|
+
* @param callback - Function invoked with an object containing the keyCode and keyName.
|
|
125
|
+
* @returns The current instance for method chaining.
|
|
114
126
|
*/
|
|
115
127
|
on(event: "keyUp", callback: (data: {
|
|
116
128
|
keyCode: number;
|
|
@@ -118,15 +130,43 @@ interface KeyboardListenerPrivate extends EventEmitter {
|
|
|
118
130
|
}) => void): this;
|
|
119
131
|
}
|
|
120
132
|
/**
|
|
121
|
-
*
|
|
133
|
+
* Class that implements a private keyboard listener.
|
|
134
|
+
* This class leverages native C++ bindings to hook into system keyboard events.
|
|
135
|
+
* The C++ layer uses global ThreadSafeFunction objects to safely dispatch events
|
|
136
|
+
* (using a dedicated monitoring thread, mutexes, and atomic flags) to JavaScript.
|
|
122
137
|
* @extends EventEmitter
|
|
123
138
|
*/
|
|
124
139
|
declare class KeyboardListenerPrivate extends EventEmitter {
|
|
140
|
+
/**
|
|
141
|
+
* Constructs the keyboard listener and sets up native callbacks.
|
|
142
|
+
* The callbacks (set via setKeyDownCallback and setKeyUpCallback) are defined in the
|
|
143
|
+
* C++ binding layer. They are responsible for invoking these JavaScript callbacks
|
|
144
|
+
* in a thread-safe manner once a key event is detected.
|
|
145
|
+
*/
|
|
125
146
|
constructor();
|
|
126
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* A singleton manager for the KeyboardListenerPrivate instance.
|
|
150
|
+
* This class ensures that only one native keyboard listener is active at any time.
|
|
151
|
+
* When the listener is destroyed, it calls unsetKeyDownCallback and unsetKeyUpCallback
|
|
152
|
+
* to clean up native resources, mirroring the cleanup logic in the C++ bindings.
|
|
153
|
+
*/
|
|
127
154
|
declare class KeyboardListener {
|
|
155
|
+
/**
|
|
156
|
+
* Holds the singleton instance of KeyboardListenerPrivate.
|
|
157
|
+
*/
|
|
128
158
|
private static listenerInstance;
|
|
159
|
+
/**
|
|
160
|
+
* Returns the singleton instance of KeyboardListenerPrivate. If not already created,
|
|
161
|
+
* it instantiates a new instance and sets up the native callbacks.
|
|
162
|
+
* @returns The active KeyboardListenerPrivate instance.
|
|
163
|
+
*/
|
|
129
164
|
static listener(): KeyboardListenerPrivate;
|
|
165
|
+
/**
|
|
166
|
+
* Destroys the current KeyboardListenerPrivate instance and cleans up native callbacks.
|
|
167
|
+
* This method calls unsetKeyDownCallback and unsetKeyUpCallback to release any
|
|
168
|
+
* native resources (such as the global ThreadSafeFunctions) and stops the monitoring thread.
|
|
169
|
+
*/
|
|
130
170
|
static destroy(): void;
|
|
131
171
|
}
|
|
132
172
|
/**
|
|
@@ -166,6 +206,11 @@ declare class OpenCV {
|
|
|
166
206
|
* @returns A new OpenCV instance with the grayscale image data.
|
|
167
207
|
*/
|
|
168
208
|
bgrToGray(): OpenCV;
|
|
209
|
+
/**
|
|
210
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
211
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
212
|
+
*/
|
|
213
|
+
equalizeHist(): OpenCV;
|
|
169
214
|
/**
|
|
170
215
|
* Draws a rectangle on the image.
|
|
171
216
|
* @param start - The starting point of the rectangle.
|
|
@@ -188,4 +233,4 @@ declare class OpenCV {
|
|
|
188
233
|
imwrite(path: string): void;
|
|
189
234
|
}
|
|
190
235
|
declare function keyPress(keyCode: number, repeat?: number): Promise<boolean>;
|
|
191
|
-
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, KeyboardListener, OpenCV };
|
|
236
|
+
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, captureScreenAsync, KeyboardListener, OpenCV };
|
package/dist/index.mjs
CHANGED
|
@@ -8,7 +8,7 @@ const nodeGypBuild = __require("node-gyp-build");
|
|
|
8
8
|
import { keyCodes, KeyCodeHelper } from "./keyCodes.mjs";
|
|
9
9
|
import { __dirnameLocal } from "./dirnameLocal.mjs";
|
|
10
10
|
const bindings = nodeGypBuild(path.resolve(__dirnameLocal, ".."));
|
|
11
|
-
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition } = bindings;
|
|
11
|
+
const { setKeyDownCallback, setKeyUpCallback, unsetKeyDownCallback, unsetKeyUpCallback, getWindowData, captureWindowN, captureScreenAsync, mouseMove, mouseClick, mouseDrag, typeString, pressKey, imread, imwrite, matchTemplate, blur, bgrToGray, drawRectangle, getRegion, textRecognition, equalizeHist } = bindings;
|
|
12
12
|
const rawPressKey = pressKey;
|
|
13
13
|
/**
|
|
14
14
|
* Captures a window and saves it to a file.
|
|
@@ -39,21 +39,36 @@ function captureScreenToFile(path) {
|
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
/**
|
|
42
|
-
*
|
|
42
|
+
* Class that implements a private keyboard listener.
|
|
43
|
+
* This class leverages native C++ bindings to hook into system keyboard events.
|
|
44
|
+
* The C++ layer uses global ThreadSafeFunction objects to safely dispatch events
|
|
45
|
+
* (using a dedicated monitoring thread, mutexes, and atomic flags) to JavaScript.
|
|
43
46
|
* @extends EventEmitter
|
|
44
47
|
*/
|
|
45
48
|
class KeyboardListenerPrivate extends EventEmitter {
|
|
49
|
+
/**
|
|
50
|
+
* Constructs the keyboard listener and sets up native callbacks.
|
|
51
|
+
* The callbacks (set via setKeyDownCallback and setKeyUpCallback) are defined in the
|
|
52
|
+
* C++ binding layer. They are responsible for invoking these JavaScript callbacks
|
|
53
|
+
* in a thread-safe manner once a key event is detected.
|
|
54
|
+
*/
|
|
46
55
|
constructor() {
|
|
47
56
|
super();
|
|
57
|
+
// Set the callback for key down events.
|
|
48
58
|
setKeyDownCallback((keyCode) => {
|
|
59
|
+
// Look up the human-readable key name from a mapping.
|
|
49
60
|
const keyName = keyCodes.get(keyCode.toString());
|
|
61
|
+
// Emit the 'keyDown' event to all registered JavaScript listeners.
|
|
50
62
|
this.emit("keyDown", {
|
|
51
63
|
keyCode,
|
|
52
64
|
keyName,
|
|
53
65
|
});
|
|
54
66
|
});
|
|
67
|
+
// Set the callback for key up events.
|
|
55
68
|
setKeyUpCallback((keyCode) => {
|
|
69
|
+
// Look up the human-readable key name from a mapping.
|
|
56
70
|
const keyName = keyCodes.get(keyCode.toString());
|
|
71
|
+
// Emit the 'keyUp' event to all registered JavaScript listeners.
|
|
57
72
|
this.emit("keyUp", {
|
|
58
73
|
keyCode,
|
|
59
74
|
keyName,
|
|
@@ -61,13 +76,33 @@ class KeyboardListenerPrivate extends EventEmitter {
|
|
|
61
76
|
});
|
|
62
77
|
}
|
|
63
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* A singleton manager for the KeyboardListenerPrivate instance.
|
|
81
|
+
* This class ensures that only one native keyboard listener is active at any time.
|
|
82
|
+
* When the listener is destroyed, it calls unsetKeyDownCallback and unsetKeyUpCallback
|
|
83
|
+
* to clean up native resources, mirroring the cleanup logic in the C++ bindings.
|
|
84
|
+
*/
|
|
64
85
|
class KeyboardListener {
|
|
86
|
+
/**
|
|
87
|
+
* Holds the singleton instance of KeyboardListenerPrivate.
|
|
88
|
+
*/
|
|
65
89
|
static listenerInstance = null;
|
|
90
|
+
/**
|
|
91
|
+
* Returns the singleton instance of KeyboardListenerPrivate. If not already created,
|
|
92
|
+
* it instantiates a new instance and sets up the native callbacks.
|
|
93
|
+
* @returns The active KeyboardListenerPrivate instance.
|
|
94
|
+
*/
|
|
66
95
|
static listener() {
|
|
67
|
-
if (!this.listenerInstance)
|
|
96
|
+
if (!this.listenerInstance) {
|
|
68
97
|
this.listenerInstance = new KeyboardListenerPrivate();
|
|
98
|
+
}
|
|
69
99
|
return this.listenerInstance;
|
|
70
100
|
}
|
|
101
|
+
/**
|
|
102
|
+
* Destroys the current KeyboardListenerPrivate instance and cleans up native callbacks.
|
|
103
|
+
* This method calls unsetKeyDownCallback and unsetKeyUpCallback to release any
|
|
104
|
+
* native resources (such as the global ThreadSafeFunctions) and stops the monitoring thread.
|
|
105
|
+
*/
|
|
71
106
|
static destroy() {
|
|
72
107
|
this.listenerInstance = null;
|
|
73
108
|
unsetKeyDownCallback();
|
|
@@ -128,6 +163,13 @@ class OpenCV {
|
|
|
128
163
|
bgrToGray() {
|
|
129
164
|
return new OpenCV(bgrToGray(this.imageData));
|
|
130
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
168
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
169
|
+
*/
|
|
170
|
+
equalizeHist() {
|
|
171
|
+
return new OpenCV(equalizeHist(this.imageData));
|
|
172
|
+
}
|
|
131
173
|
/**
|
|
132
174
|
* Draws a rectangle on the image.
|
|
133
175
|
* @param start - The starting point of the rectangle.
|
|
@@ -174,4 +216,4 @@ function keyPress(keyCode, repeat) {
|
|
|
174
216
|
return resolve(true);
|
|
175
217
|
});
|
|
176
218
|
}
|
|
177
|
-
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, KeyboardListener, OpenCV };
|
|
219
|
+
export { getWindowData, captureWindow, captureWindowN, mouseMove, mouseClick, mouseDrag, typeString, keyPress, rawPressKey, KeyCodeHelper, textRecognition, captureScreenToFile, captureScreenAsync, KeyboardListener, OpenCV };
|
package/package.json
CHANGED
|
Binary file
|
package/src/cpp/main.cpp
CHANGED
|
@@ -26,6 +26,7 @@ Napi::Object Init(Napi::Env env, Napi::Object exports)
|
|
|
26
26
|
exports.Set("matchTemplate", Napi::Function::New(env, MatchTemplate));
|
|
27
27
|
exports.Set("blur", Napi::Function::New(env, Blur));
|
|
28
28
|
exports.Set("bgrToGray", Napi::Function::New(env, BgrToGray));
|
|
29
|
+
exports.Set("equalizeHist", Napi::Function::New(env, EqualizeHist));
|
|
29
30
|
exports.Set("drawRectangle", Napi::Function::New(env, DrawRectangle));
|
|
30
31
|
exports.Set("getRegion", Napi::Function::New(env, GetRegion));
|
|
31
32
|
exports.Set("textRecognition", Napi::Function::New(env, TextRecognition));
|
package/src/cpp/opencv.cpp
CHANGED
|
@@ -234,6 +234,52 @@ Napi::Value BgrToGray(const Napi::CallbackInfo &info)
|
|
|
234
234
|
return result;
|
|
235
235
|
}
|
|
236
236
|
|
|
237
|
+
Napi::Value EqualizeHist(const Napi::CallbackInfo &info)
|
|
238
|
+
{
|
|
239
|
+
Napi::Env env = info.Env();
|
|
240
|
+
|
|
241
|
+
if (info.Length() < 1 || !info[0].IsObject())
|
|
242
|
+
{
|
|
243
|
+
Napi::TypeError::New(env, "Invalid arguments. Expected: (object)").ThrowAsJavaScriptException();
|
|
244
|
+
return env.Null();
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
Napi::Object srcObj = info[0].As<Napi::Object>();
|
|
248
|
+
|
|
249
|
+
if (!srcObj.Has("data") || !srcObj.Has("width") || !srcObj.Has("height"))
|
|
250
|
+
{
|
|
251
|
+
Napi::TypeError::New(env, "Invalid image data object. Expected properties: 'data', 'width', 'height'").ThrowAsJavaScriptException();
|
|
252
|
+
return env.Null();
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (!srcObj.Get("data").IsTypedArray())
|
|
256
|
+
{
|
|
257
|
+
Napi::TypeError::New(env, "TypedArray expected for 'data' property").ThrowAsJavaScriptException();
|
|
258
|
+
return env.Null();
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
int width = srcObj.Get("width").ToNumber().Int32Value();
|
|
262
|
+
int height = srcObj.Get("height").ToNumber().Int32Value();
|
|
263
|
+
|
|
264
|
+
cv::Mat src(height, width, CV_8UC1, srcObj.Get("data").As<Napi::TypedArray>().ArrayBuffer().Data());
|
|
265
|
+
cv::Mat dst;
|
|
266
|
+
|
|
267
|
+
cv::equalizeHist(src, dst);
|
|
268
|
+
|
|
269
|
+
Napi::Object result = Napi::Object::New(env);
|
|
270
|
+
size_t totalBytes = dst.total() * dst.elemSize();
|
|
271
|
+
Napi::ArrayBuffer arrayBuffer = Napi::ArrayBuffer::New(env, totalBytes);
|
|
272
|
+
Napi::Uint8Array uint8Array = Napi::Uint8Array::New(env, totalBytes, arrayBuffer, 0);
|
|
273
|
+
|
|
274
|
+
memcpy(uint8Array.Data(), dst.data, totalBytes);
|
|
275
|
+
result.Set("width", width);
|
|
276
|
+
result.Set("height", height);
|
|
277
|
+
result.Set("data", uint8Array);
|
|
278
|
+
|
|
279
|
+
return result;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
|
|
237
283
|
Napi::Value Blur(const Napi::CallbackInfo &info)
|
|
238
284
|
{
|
|
239
285
|
Napi::Env env = info.Env();
|
package/src/index.mts
CHANGED
|
@@ -120,7 +120,7 @@ export type Blur = (
|
|
|
120
120
|
sizeY: number
|
|
121
121
|
) => ImageData;
|
|
122
122
|
export type BgrToGray = (image: ImageData) => ImageData;
|
|
123
|
-
|
|
123
|
+
export type EqualizeHist = (image: ImageData) => ImageData;
|
|
124
124
|
export type DrawRectangle = (
|
|
125
125
|
image: ImageData,
|
|
126
126
|
start: Point,
|
|
@@ -153,7 +153,8 @@ const {
|
|
|
153
153
|
bgrToGray,
|
|
154
154
|
drawRectangle,
|
|
155
155
|
getRegion,
|
|
156
|
-
textRecognition
|
|
156
|
+
textRecognition,
|
|
157
|
+
equalizeHist
|
|
157
158
|
}: {
|
|
158
159
|
setKeyDownCallback: SetKeyCallback;
|
|
159
160
|
setKeyUpCallback: SetKeyCallback;
|
|
@@ -175,6 +176,7 @@ const {
|
|
|
175
176
|
getRegion: GetRegion;
|
|
176
177
|
textRecognition: TextRecognition;
|
|
177
178
|
captureScreenAsync: CaptureScreenAsync;
|
|
179
|
+
equalizeHist: EqualizeHist
|
|
178
180
|
} = bindings;
|
|
179
181
|
|
|
180
182
|
const rawPressKey = pressKey;
|
|
@@ -385,6 +387,15 @@ class OpenCV {
|
|
|
385
387
|
return new OpenCV(bgrToGray(this.imageData));
|
|
386
388
|
}
|
|
387
389
|
|
|
390
|
+
/**
|
|
391
|
+
* Equalize the Histogram by using the OpenCV function cv::equalizeHist.
|
|
392
|
+
* @returns A new OpenCV instance with the equalized image data.
|
|
393
|
+
*/
|
|
394
|
+
equalizeHist() {
|
|
395
|
+
return new OpenCV(equalizeHist(this.imageData));
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
|
|
388
399
|
/**
|
|
389
400
|
* Draws a rectangle on the image.
|
|
390
401
|
* @param start - The starting point of the rectangle.
|
|
@@ -449,6 +460,7 @@ export {
|
|
|
449
460
|
KeyCodeHelper,
|
|
450
461
|
textRecognition,
|
|
451
462
|
captureScreenToFile,
|
|
463
|
+
captureScreenAsync,
|
|
452
464
|
KeyboardListener,
|
|
453
465
|
OpenCV
|
|
454
466
|
};
|