Posts: 1,192
Threads: 277
Joined: Jul 2022
11-03-2025, 04:41 AM
(This post was last modified: 11-03-2025, 04:42 AM by Davider.)
I want to implement a feature:
for example, I need to input three different pieces of text into Notepad in three separate steps. Before each input, the mouse pointer must click on a specific position within the Notepad window.
Note: The pointer's movement trajectory must be unique each time, not a straight line, but a curved motion.
Is this possible? Thank you in advance for any suggestions and help.
Posts: 12,240
Threads: 144
Joined: Dec 2002
MouseMoveRandomCurve(new(500, 500), 0.2);
static void MouseMoveRandomCurve(POINT xy, double curveFactor = 0.15) {
var start = mouse.xy;
int steps = 50 + Random.Shared.Next(30);
double dx = xy.x - start.x, dy = xy.y - start.y;
double dist = Math.Sqrt(dx * dx + dy * dy);
if (dist < 1) return;
// normalize direction
double dirX = dx / dist, dirY = dy / dist;
// perpendicular direction
double px = -dirY, py = dirX;
// random curve parameters
double curveAmp = dist * curveFactor; // user-controlled curvature
double curvePhase = Random.Shared.NextDouble() * Math.PI * 2;
double curveFreq = _NextDouble(0.7, 1.3);
for (int i = 1; i <= steps; i++) {
double t = (double)i / steps;
double tt = t * t * (3 - 2 * t); // smooth ease-in-out
double fade = Math.Sin(t * Math.PI); // zero at start/end
double offset = Math.Sin(tt * Math.PI * curveFreq + curvePhase) * fade * curveAmp;
double x = start.x + dx * tt + px * offset;
double y = start.y + dy * tt + py * offset;
// clamp to screen
var r = screen.of((int)x, (int)y).Rect;
x = Math.Clamp(x, r.left, r.right - 1);
y = Math.Clamp(y, r.top, r.bottom - 1);
mouse.move((int)x, (int)y);
wait.ms(8);
}
mouse.move(xy);
static double _NextDouble(double min, double max)
=> min + (max - min) * Random.Shared.NextDouble();
}
Thanks to ChatGPT.
Posts: 1,192
Threads: 277
Joined: Jul 2022