node-native-win-utils 2.2.2 → 2.2.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 +2 -0
- package/dist/index.d.mts +1 -1
- package/package.json +1 -1
- package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
- package/src/cpp/mouse.cpp +23 -14
- package/src/index.mts +1 -1
package/README.md
CHANGED
|
@@ -75,6 +75,8 @@ keyPress(KeyCodeHelper.Enter, 2); // twice
|
|
|
75
75
|
mouseMove(500, 300);
|
|
76
76
|
mouseClick(); // left click
|
|
77
77
|
mouseClick("right");
|
|
78
|
+
mouseClick("left", "down") // left button down
|
|
79
|
+
mouseClick("left", "up") // left button up
|
|
78
80
|
mouseDrag(100, 100, 800, 600, 50); // optional speed
|
|
79
81
|
|
|
80
82
|
typeString("Hello from Node!", 30); // 30ms delay per char
|
package/dist/index.d.mts
CHANGED
|
@@ -51,7 +51,7 @@ export type MouseMove = (posX: number, posY: number) => boolean;
|
|
|
51
51
|
/**
|
|
52
52
|
* Function type for simulating a mouse click.
|
|
53
53
|
*/
|
|
54
|
-
export type MouseClick = (button?: "left" | "middle" | "right") => boolean;
|
|
54
|
+
export type MouseClick = (button?: "left" | "middle" | "right", type?: "down" | "up" | "click") => boolean;
|
|
55
55
|
/**
|
|
56
56
|
* Function type for simulating typing.
|
|
57
57
|
*/
|
package/package.json
CHANGED
|
Binary file
|
package/src/cpp/mouse.cpp
CHANGED
|
@@ -69,12 +69,13 @@ Napi::Value MoveMouse(const Napi::CallbackInfo &info)
|
|
|
69
69
|
Napi::Value ClickMouse(const Napi::CallbackInfo &info)
|
|
70
70
|
{
|
|
71
71
|
Napi::Env env = info.Env();
|
|
72
|
-
std::string button;
|
|
73
|
-
|
|
74
|
-
if (info.Length()
|
|
75
|
-
button = "left";
|
|
76
|
-
else
|
|
72
|
+
std::string button = "left";
|
|
73
|
+
std::string type = "click";
|
|
74
|
+
if (info.Length() >= 1 && info[0].IsString())
|
|
77
75
|
button = info[0].As<Napi::String>();
|
|
76
|
+
if(info.Length() >= 2 && info[1].IsString())
|
|
77
|
+
type = info[1].As<Napi::String>();
|
|
78
|
+
|
|
78
79
|
|
|
79
80
|
WORD downFlag = 0, upFlag = 0;
|
|
80
81
|
|
|
@@ -98,15 +99,23 @@ Napi::Value ClickMouse(const Napi::CallbackInfo &info)
|
|
|
98
99
|
Napi::TypeError::New(env, "Invalid button name").ThrowAsJavaScriptException();
|
|
99
100
|
return env.Null();
|
|
100
101
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
102
|
+
UINT sent = 0;
|
|
103
|
+
INPUT inputsClick[2] = {};
|
|
104
|
+
inputsClick[0].type = INPUT_MOUSE;
|
|
105
|
+
inputsClick[0].mi.dwFlags = downFlag;
|
|
106
|
+
inputsClick[1].type = INPUT_MOUSE;
|
|
107
|
+
inputsClick[1].mi.dwFlags = upFlag;
|
|
108
|
+
inputsClick[1].mi.time = 0;
|
|
109
|
+
inputsClick[0].mi.time = 0;
|
|
110
|
+
INPUT singleInput[1] = {};
|
|
111
|
+
singleInput[0].type = INPUT_MOUSE;
|
|
112
|
+
WORD flag = (type == "down") ? downFlag : upFlag;
|
|
113
|
+
singleInput[0].mi.dwFlags = flag;
|
|
114
|
+
|
|
115
|
+
if(type == "click")
|
|
116
|
+
sent = SendInput(2, inputsClick, sizeof(INPUT));
|
|
117
|
+
else
|
|
118
|
+
sent = SendInput(1, singleInput, sizeof(INPUT));
|
|
110
119
|
if (sent == 0)
|
|
111
120
|
return Napi::Boolean::New(env, false);
|
|
112
121
|
return Napi::Boolean::New(env, true);
|
package/src/index.mts
CHANGED
|
@@ -68,7 +68,7 @@ export type MouseMove = (posX: number, posY: number) => boolean;
|
|
|
68
68
|
/**
|
|
69
69
|
* Function type for simulating a mouse click.
|
|
70
70
|
*/
|
|
71
|
-
export type MouseClick = (button?: "left" | "middle" | "right") => boolean;
|
|
71
|
+
export type MouseClick = (button?: "left" | "middle" | "right", type?: "down" | "up" | "click") => boolean;
|
|
72
72
|
|
|
73
73
|
/**
|
|
74
74
|
* Function type for simulating typing.
|