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

标签 c# ui-automation

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

最佳答案

卫生部!当你困了的时候一定要停止工作并上床 sleep 。

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

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

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

关于c# - InputSimulator 在 2 点之间平滑线性鼠标移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54701512/

相关文章:

automated-tests - 在 Katalon Studio 中找不到 "Global Variable view"

c# - 使用列表作为线程启动例程的参数时出现索引超出范围错误

c# - 创建一个匹配反射类型的方法

c# - ASP.NET Web API Controller 最佳实践 - Action 定义

c# - 模拟后回退到子进程的默认用户

ui-automation - Android运行时权限-如何测试UI

python - 在 python 中识别 windows/linux GUI 中的文本以进行自动化测试