【发布时间】:2017-11-12 00:49:46
【问题描述】:
我试图在 Pyautogui 中以贝塞尔曲线运动来移动鼠标,以模拟更多的人类运动,如下所示:
pyautogui 中有一些补间/缓动函数,但没有一个代表贝塞尔曲线类型的运动。我创建了一个小脚本来计算它在最终到达目的地之前会到达的随机位置。
不幸的是,每个目的地鼠标都会暂时停止。
import pyautogui
import time
import random
print "Randomized Mouse Started."
destx = 444;
desty = 631;
x, y = pyautogui.position() # Current Position
moves = random.randint(2,4)
pixelsx = destx-x
pixelsy = desty-y
if moves >= 4:
moves = random.randint(2,4)
avgpixelsx = pixelsx/moves
avgpixelsy = pixelsy/moves
print "Pixels to be moved X: ", pixelsx," Y: ",pixelsy, "Number of mouse movements: ", moves, "Avg Move X: ", avgpixelsx, " Y: ", avgpixelsy
while moves > 0:
offsetx = (avgpixelsx+random.randint(-8, random.randint(5,10)));
offsety = (avgpixelsy+random.randint(-8, random.randint(5,10)));
print x + offsetx, y + offsety, moves
pyautogui.moveTo(x + offsetx, y + offsety, duration=0.2)
moves = moves-1
avgpixelsx = pixelsx / moves
avgpixelsy = pixelsy / moves
信息:
- Windows 10
- Python 2.7
- 愿意使用其他库,如有需要,Python版本
我看过这个帖子:python random mouse movements
但不知道如何定义“开始和停止”位置。答案与我正在寻找的非常接近。
关于如何实现这一点的任何想法?
【问题讨论】:
-
你能解释一下你的代码吗?我正在做类似的事情