本文介绍了InputSimulator 在 2 点之间平滑线性鼠标移动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm struggling to figure out why the below function is only ever moving my mouse from 0, 0 screen coords, to my final destination, even though Cursor.Position is returning the correct screen coords. If anybody could enlighten me i'd be most grateful.

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

推荐答案

DOH!困了就停止工作然后上床睡觉.

DOH! Always stop working when you're sleepy and go to bed.

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

The InputSimulator library requires that you translate coordinates like so:

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

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

I was converting the end coordinates but completely forgot to translate the starting coordinates, derp.

这篇关于InputSimulator 在 2 点之间平滑线性鼠标移动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 08:34