我想在给定时间内将光标位置从当前位置移动到给定(X,Y)。 我试过这种方式 -
import win32api as api
import win32gui as gui
import time
import math
def moveMouse(x,y):
api.SetCursorPos((x,y))
def move_slowly(x2,y2,total_time):
x0, y0 = api.GetCursorPos()
draw_steps = int(math.sqrt(math.pow(x0-x2,2) + math.pow(y0-y2,2)))
dx = (x2-x0)/draw_steps #how much x to move each step
dy = (y2-y0)/draw_steps #how much y to move each step
dt = total_time/draw_steps #time between each step
for n in range(draw_steps):
x = int(x0+dx*n)
y = int(y0+dy*n)
moveMouse(x,y)
time.sleep(dt)
但时间总是有点过时。 我听说可以使用autopy完成,但无论我如何尝试 - 我都无法下载该库。 有什么帮助吗?