繁体   English   中英

InputSimulator 在 2 点之间平滑线性鼠标移动

[英]InputSimulator smooth linear mouse movement between 2 points

我正在努力弄清楚为什么下面的函数只会将我的鼠标从 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

哦! 当你困了时总是停止工作并上床睡觉。

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

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM