控制发送输入鼠标移动速度

时间:2012-10-28 20:00:22

标签: c# winforms mouse sendinput

使用Sendinput方法时是否可以控制鼠标指针的速度?

例如,这是我的代码:

    public static void ClickMouseDOWN(int x, int y)
    {
        INPUT mouseInput = new INPUT();
        mouseInput.type = (int)InputType.INPUT_MOUSE;
        mouseInput.mi.dx = CalculateAbsoluteCoordinateX(x);
        mouseInput.mi.dy = CalculateAbsoluteCoordinateY(y);
        mouseInput.mi.mouseData = 0;

// mouse teleports instantly
            mouseInput.mi.dwFlags = (int)MOUSEEVENTF.MOVE | (int)MOUSEEVENTF.ABSOLUTE;
            SendInput(1, new INPUT[] { mouseInput }, Marshal.SizeOf(mouseInput));
// mouse teleports instantly

        mouseInput.mi.dwFlags = (int)MOUSEEVENTF.LEFTDOWN;
        SendInput(1, new INPUT[] { mouseInput }, Marshal.SizeOf(mouseInput));

    }

以下代码执行MouseMovement +鼠标按钮按(向下)命令,但问题是指针传送到位置(int x,int y),而不是以一定的速度移动到它。

我希望能够控制这种速度。

1 个答案:

答案 0 :(得分:-1)

我找不到答案,所以最后我不得不使用原生方法:

Cursor.Position = new Point(x, y);

我可以在将光标移动到新位置时指定Thread.Sleep(Z)