public static API_InputSimulator mouse_MoveTo(this API_InputSimulator inputSimulator, double x, double y, bool animate) { x += inputSimulator.Mouse_MoveTo_X_Offset; y += inputSimulator.Mouse_MoveTo_Y_Offset; var currentPosition = inputSimulator.mouse_CurrentPosition(); inputSimulator.mouse_MoveBy(x - currentPosition.X, y - currentPosition.Y, animate); return(inputSimulator); }
public static API_InputSimulator mouse_MoveBy(this API_InputSimulator inputSimulator, double x, double y, bool animate) { if (x != 0 || y != 0) { "moving mouse by:{0} {1}".info(x, y); double currentX = inputSimulator.mouse_CurrentPosition().X; double currentY = inputSimulator.mouse_CurrentPosition().Y; double numberOfSteps = (Math.Abs(x) > Math.Abs(y)) ? Math.Abs(x) : Math.Abs(y); double xStep = ((x != 0) ? x / numberOfSteps : 0) * inputSimulator.Move_SkipValue; double yStep = ((y != 0) ? y / numberOfSteps : 0) * inputSimulator.Move_SkipValue; for (int i = 0; i < numberOfSteps; i += inputSimulator.Move_SkipValue) { currentX += xStep; //(x >0) ? -xStep : -xStep; currentY += yStep; //(y >0) ? -yStep : -yStep; inputSimulator.mouse_SetPosition(currentX, currentY, animate); } } return(inputSimulator); }