我需要用可见的光标移动将鼠标光标从坐标(800,300)移至(100,600)。
我怎样才能做到这一点? (我只需要模拟运动-我通过autopy模块获取鼠标位置)

最佳答案

直接来自docs

import autopy

autopy.mouse.move(800, 300)
autopy.mouse.smooth_move(100, 600)


这首先移动到该位置,然后将鼠标线性滑动到第二个位置。结合多个暂停,您可以使用autopy.mouse.move根据需要缓慢或快速地移动。

根据要求编辑:为了更好地控制smooth_move,您可以自己设置鼠标位置。在这里,我将total_time设置为5.00秒,但是您可以根据需要将其更改为最快的速度。

from __future__ import division
import autopy
import time

x0, y0 = 800, 300
xf, yf = 100, 600

total_time = 5.00  # in seconds
draw_steps = 1000  # total times to update cursor

dx = (xf-x0)/draw_steps
dy = (yf-y0)/draw_steps
dt = total_time/draw_steps

for n in xrange(draw_steps):
    x = int(x0+dx*n)
    y = int(y0+dy*n)
    autopy.mouse.move(x,y)
    time.sleep(dt)

关于python - 模拟光标从X,Y到X,Y的运动,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28004698/

10-09 13:39