如何在 PyAutoGUI 上使用具有持续时间和补间功能的 moveTo 和 locateOnScreen?
How to use moveTo and locateOnScreen with duration and tween features on PyAutoGUI?
我正在使用带坐标的 moveTo
函数,但我注意到有时坐标会发生变化,因此每次手动获取这些坐标并不像我想要的那样实用。
所以我试图将 moveTo
函数与 locateOnScreen
一起使用,问题是:如果我添加 tween 和 duration 功能我遇到了错误。
我正在使用:
pyautogui.moveTo(pyautogui.locateOnScreen(1677, 610, confidence=0.8), np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
那我改成:
Img = 'test.png'
pyautogui.moveTo(pyautogui.locateOnScreen(Img, confidence=0.8), np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
但是使用上面的函数我得到了错误:When passing a sequence for firstArg, secondArg must not be passed and default to None (received 1.4511874585715279)
。
该功能只有在我这样做时才有效:
pyautogui.moveTo(pyautogui.locateOnScreen(Img))
但是如果我这样使用,鼠标光标会立即移动到我不想要的新坐标。我希望更像是一种“人类”行为。
如何在 PyAutoGUI 上使用 moveTo
和 locateOnScreen
的持续时间和补间功能?
根据 pyautogui here 的文档,我使用了一种使用 pyautogui.center
函数的不同方法:
button7point = pyautogui.center(pyautogui.locateOnScreen('calc7key.png'))
输出:
button7point.x
1441
button7point.y
582
但是正如@jasonharper 在评论中提到的,我可以通过将 None
添加到参数中直接从函数 locateOnScreen
中找到图像,所以答案是:
Img = 'test.png'
pyautogui.moveTo(pyautogui.locateOnScreen(Img, confidence=0.8), None, np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
我正在使用带坐标的 moveTo
函数,但我注意到有时坐标会发生变化,因此每次手动获取这些坐标并不像我想要的那样实用。
所以我试图将 moveTo
函数与 locateOnScreen
一起使用,问题是:如果我添加 tween 和 duration 功能我遇到了错误。
我正在使用:
pyautogui.moveTo(pyautogui.locateOnScreen(1677, 610, confidence=0.8), np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
那我改成:
Img = 'test.png'
pyautogui.moveTo(pyautogui.locateOnScreen(Img, confidence=0.8), np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
但是使用上面的函数我得到了错误:When passing a sequence for firstArg, secondArg must not be passed and default to None (received 1.4511874585715279)
。
该功能只有在我这样做时才有效:
pyautogui.moveTo(pyautogui.locateOnScreen(Img))
但是如果我这样使用,鼠标光标会立即移动到我不想要的新坐标。我希望更像是一种“人类”行为。
如何在 PyAutoGUI 上使用 moveTo
和 locateOnScreen
的持续时间和补间功能?
根据 pyautogui here 的文档,我使用了一种使用 pyautogui.center
函数的不同方法:
button7point = pyautogui.center(pyautogui.locateOnScreen('calc7key.png'))
输出:
button7point.x
1441
button7point.y
582
但是正如@jasonharper 在评论中提到的,我可以通过将 None
添加到参数中直接从函数 locateOnScreen
中找到图像,所以答案是:
Img = 'test.png'
pyautogui.moveTo(pyautogui.locateOnScreen(Img, confidence=0.8), None, np.random.uniform(0.8,2), pyautogui.easeInOutQuad)