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 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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-native-win-utils",
3
- "version": "2.2.2",
3
+ "version": "2.2.3",
4
4
  "author": "Andrew K.",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/T-Rumibul/node-native-win-utils.git",
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() < 1 || !info[0].IsString())
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
- // Perform the mouse click
103
- INPUT inputs[2] = {};
104
- inputs[0].type = INPUT_MOUSE;
105
- inputs[0].mi.dwFlags = downFlag;
106
- inputs[1].type = INPUT_MOUSE;
107
- inputs[1].mi.dwFlags = upFlag;
108
-
109
- UINT sent = SendInput(2, inputs, sizeof(INPUT));
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.