首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >InputSimulator在两个点之间平滑的线性鼠标移动

InputSimulator在两个点之间平滑的线性鼠标移动
EN

Stack Overflow用户
提问于 2019-02-15 09:28:58
回答 2查看 949关注 0票数 2

我很难弄明白为什么下面的函数只把我的鼠标从0,0个屏幕坐标移动到我的最终目的地,尽管Cursor.Position返回了正确的屏幕坐标。如果有人能开导我,我将不胜感激。

代码语言:javascript
复制
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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-02-15 22:05:04

多!当你困了的时候,一定要停止工作,去睡觉。

InputSimulator库要求您按如下方式转换坐标:

代码语言:javascript
复制
int startX = 65535 * Cursor.Position.X / Screen.PrimaryScreen.Bounds.Width;
int startY = 65535 * Cursor.Position.Y / Screen.PrimaryScreen.Bounds.Height;

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

票数 4
EN

Stack Overflow用户

发布于 2019-02-17 20:46:40

FlaUI允许鼠标平滑移动。下面是FlaUI中的Mouse类,以供参考。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54701512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档