gpt4 book ai didi

vb.net - 让鼠标光标移动到一个位置?

转载 作者:行者123 更新时间:2023-12-02 00:02:12 25 4
gpt4 key购买 nike

我知道如何使用以下方法使光标移动到某个位置:

Cursor.Position = New Point(XPosition, YPosition)

但这样做会使它立即移动到那里,我希望它以设定的速度从当前位置移动到新位置。

速度将由两个因素决定:

1 - 当前位置和新位置之间的距离 - EG。与以 10px/s 的速度从 0X 到 1000X 相比,以 5px/s 的速度从 0X 到 500X。

2 - 到达目标位置的有限时间。

我只知道这样做的一种困惑的方式类似于:

If Cursor.Position.X < XPosition Then 
Dim Speed as Integer = XPosition - Cursor.Position.X
While Cursor.Position.X < XPosition
Cursor.Position = New Point(Cursor.Position.X + Speed, Blah..)
End While
End If
'Etc..

这将需要多个 If 语句来检查当前 X/Y 位置是否高于/低于目标 X/Y 位置。

有什么方法可以让代码更简洁吗?

最佳答案

听起来您需要直线的参数方程:

x = x1 + (x2-x1)*t

在哪里
x1 = 开始 x,
x2 = 结束 x,并且
t = 0 和 1 之间的时间。

因此,如果您希望光标在 10 秒内从 x1(10,20) 移动到 x2(30,60)...

1 秒:
x = 10 + (30-10)*.1 ; x = 12
y = 20 + (60-20)*.1 ; y = 24
2 秒内:
x = 10 + (30-10)*.2 ; x = 14
y = 20 + (60-20)*.2 ; y = 28
3 秒内:
x = 10 + (30-10)*.3 ; x = 16
y = 20 + (60-20)*.3 ; y = 32

编辑:
这是一个实际的想法(不经常使用 VB,所以它并不完美)
http://ideone.com/c9iLTA

关于vb.net - 让鼠标光标移动到一个位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20656102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com