Python: Thread 中的 pyautogui 鼠标移动缓慢且不可靠
Python: pyautogui mouse movement in Thread is slow and unreliable
我正在尝试自动将一些鼠标移动到 Python 中的某个位置 3。
为此,我使用模块 pyclicker
,特别是模块中的 HumanClicker
class。它使用一种算法来计算鼠标移动的 'human-like' 点流。
为了沿着计算点实际移动它,它使用 pyautogui.moveTo(). From pyclicker.HumanClicker:
def move(self, toPoint, duration=2, humanCurve=None):
fromPoint = pyautogui.position()
if not humanCurve:
humanCurve = HumanCurve(fromPoint, toPoint)
pyautogui.PAUSE = duration / len(humanCurve.points)
for point in humanCurve.points:
pyautogui.moveTo(point)
我通过移动鼠标并加快速度 up/slowing 得到了一些非常好的结果,但是使用 pyautogui 移动鼠标(因此也使用了这个 HumanClicker)会锁定程序,直到它完成移动。为了解决这个问题,我在需要时将鼠标移动的处理放到了一个单独的线程中。我调用 move()
:
的代码
def move(self, location, time):
try:
hc = HumanClicker()
hc.move(location, time)
except TypeError:
pass
位置是 (x, y) tuple
,时间是浮点数(当前为 0.2)。穿线运动是有效的,但它会显着减慢运动速度并使其变得更多 erratic/stuttery(两者都随着它必须行进的距离呈指数增长)。以任何方式对其进行线程化都会产生相同的结果。如果需要我可以提供运动记录。
这种 down/stuttering 交互变慢有什么具体原因吗?
是否有一个模块可以替换 pyautogui 以使其在线程中没有这些问题?
或者有其他方法可以解决这个问题吗?
我不知道你是否仍然感兴趣,但我在 this issue 上发现了问题。
显然 moveTo() 函数定义为 def moveTo(x=None, y=None, duration=0.0, tween=linear, logScreenshot=False, _pause=True):
因此,只需在您的通话中添加参数 _pause=False
即可解决问题,就像我遇到的那样。
我正在尝试自动将一些鼠标移动到 Python 中的某个位置 3。
为此,我使用模块 pyclicker
,特别是模块中的 HumanClicker
class。它使用一种算法来计算鼠标移动的 'human-like' 点流。
为了沿着计算点实际移动它,它使用 pyautogui.moveTo(). From pyclicker.HumanClicker:
def move(self, toPoint, duration=2, humanCurve=None):
fromPoint = pyautogui.position()
if not humanCurve:
humanCurve = HumanCurve(fromPoint, toPoint)
pyautogui.PAUSE = duration / len(humanCurve.points)
for point in humanCurve.points:
pyautogui.moveTo(point)
我通过移动鼠标并加快速度 up/slowing 得到了一些非常好的结果,但是使用 pyautogui 移动鼠标(因此也使用了这个 HumanClicker)会锁定程序,直到它完成移动。为了解决这个问题,我在需要时将鼠标移动的处理放到了一个单独的线程中。我调用 move()
:
def move(self, location, time):
try:
hc = HumanClicker()
hc.move(location, time)
except TypeError:
pass
位置是 (x, y) tuple
,时间是浮点数(当前为 0.2)。穿线运动是有效的,但它会显着减慢运动速度并使其变得更多 erratic/stuttery(两者都随着它必须行进的距离呈指数增长)。以任何方式对其进行线程化都会产生相同的结果。如果需要我可以提供运动记录。
这种 down/stuttering 交互变慢有什么具体原因吗?
是否有一个模块可以替换 pyautogui 以使其在线程中没有这些问题?
或者有其他方法可以解决这个问题吗?
我不知道你是否仍然感兴趣,但我在 this issue 上发现了问题。
显然 moveTo() 函数定义为 def moveTo(x=None, y=None, duration=0.0, tween=linear, logScreenshot=False, _pause=True):
因此,只需在您的通话中添加参数 _pause=False
即可解决问题,就像我遇到的那样。