【问题标题】:InputSimulator smooth linear mouse movement between 2 pointsInputSimulator 在 2 点之间平滑的线性鼠标移动
【发布时间】:2019-07-09 03:15:19
【问题描述】:

我很难弄清楚为什么下面的函数只会将我的鼠标从 0、0 屏幕坐标移动到我的最终目的地,即使 Cursor.Position 正在返回正确的屏幕坐标。如果有人能启发我,我将不胜感激。

public void MoveAndClick(int x, int y, int steps)
{
    Point start = Cursor.Position;
    PointF iterPoint = start;

    PointF slope = new PointF(x - start.X, y - start.Y);
    slope.X = slope.X / steps;
    slope.Y = slope.Y / steps;

    for(int i=0; i<steps; i++)
    {
        iterPoint = new PointF(iterPoint.X + slope.X, iterPoint.Y + slope.Y);
        inputSim.Mouse.MoveMouseTo(iterPoint.X, iterPoint.Y);
        Thread.Sleep(10);
    }

    inputSim.Mouse.MoveMouseTo(x, y);
    inputSim.Mouse.RightButtonDown();
    inputSim.Mouse.RightButtonUp();
}

取自https://stackoverflow.com/a/913703/2014393

【问题讨论】:

    标签: c# ui-automation inputsimulator


    【解决方案1】:

    DOH!当你困倦并上床睡觉时,请务必停止工作。

    InputSimulator 库要求您像这样转换坐标:

    int startX = 65535 * Cursor.Position.X / Screen.PrimaryScreen.Bounds.Width;
    int startY = 65535 * Cursor.Position.Y / Screen.PrimaryScreen.Bounds.Height;
    

    我正在转换结束坐标,但完全忘记转换起始坐标,derp。

    【讨论】:

      【解决方案2】:

      FlaUI 允许鼠标平滑移动。这里是 FlaUI 中的Mouse 类供参考。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-10-14
        • 2022-06-22
        • 1970-01-01
        • 2021-06-10
        • 2016-08-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多