.moveTo()
has two other parameters you can pass to help mimic human behavior, duration
and tween
. The first is how long it takes to get to the specified point, the second one changes its behavior such as: start fast and end slow, start slow and end fast etc...
Check out this section for reference.
I also imported random
to create a random float to pass for the duration
parameter, I think it helps make the mouse have more humanlike behavior.
from random import *
import pyautogui as py
py.moveTo(720, 360, uniform(0.6, 2.7), py.easeOutQuad)
py.moveTo(450, 900, uniform(0.6, 2.7), py.easeOutBack)
py.moveTo(360, 720, uniform(0.6, 2.7), py.easeInOutQuad)
If you are using an IDE, type pyautogui.ease
(or py.ease
) and you'll see that popup window which shows you all the variations you can try.
As a side note, human mouse behavior often has a curve to it and .moveTo()
moves in a linear line. This won't be a problem unless whatever program you're interacting with doesn't want robotic behavior (such as online video games). They could detect that all your movement is linear and then ban your account so be aware (or maybe make your own function that adds a curve to the mouse movement).