I am demoing a piece of software and want to build a mouse \'mover\' function so that I can basically automate the process. I want to create realistic mouse movements but a
You can try this.
public static class Mouse
{
private const float MOUSE_SMOOTH = 200f;
public static void MoveTo(int targetX, int targetY)
{
var targetPosition = new Point(targetX, targetY);
var curPos = Cursor.Position;
var diffX = targetPosition.X - curPos.X;
var diffY = targetPosition.Y - curPos.Y;
for (int i = 0; i <= MOUSE_SMOOTH; i++)
{
float x = curPos.X + (diffX / MOUSE_SMOOTH * i);
float y = curPos.Y + (diffY / MOUSE_SMOOTH * i);
Cursor.Position = new Point((int)x, (int)y);
Thread.Sleep(1);
}
if (Cursor.Position != targetPosition)
{
MoveTo(targetPosition.X, targetPosition.Y);
}
}
}