I was using the moveTo
function with coordinates, but I notice that sometimes the coordinates are changed, so getting those coordinates manually every time is not being that practical as I wanted.
So I'm trying to use the moveTo
function with locateOnScreen
, the problem is: if I add the tween and duration feature I got an error.
I was using:
pyautogui.moveTo(pyautogui.locateOnScreen(1677, 610, confidence=0.8), np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
Then I changed to:
Img = 'test.png'
pyautogui.moveTo(pyautogui.locateOnScreen(Img, confidence=0.8), np.random.uniform(0.8,2), pyautogui.easeInOutQuad)
But with the function above I'm getting the error: When passing a sequence for firstArg, secondArg must not be passed and default to None (received 1.4511874585715279)
.
The function only works if I do this:
pyautogui.moveTo(pyautogui.locateOnScreen(Img))
But if I use this way, the mouse cursor will instantly move to the new coordinates which I don't want. I would expect more like a "human" behavior.
How to use moveTo
and locateOnScreen
with duration and tween features on PyAutoGUI?
Following the documentation from pyautogui here, I was using a different approach that was using pyautogui.center
function:
button7point = pyautogui.center(pyautogui.locateOnScreen('calc7key.png'))
Output:
button7point.x
1441
button7point.y
582
But as @jasonharper mentioned in the comments, I was able to find the image directly from the function locateOnScreen
just by add None
to the parameter, so the answer is:
Img = 'test.png'
pyautogui.moveTo(pyautogui.locateOnScreen(Img, confidence=0.8), None, np.random.uniform(0.8,2), pyautogui.easeInOutQuad)