Auto Clicker

Pyautogui (Automation)

Install pyautogui library:


Before we can make our auto clicker we must install the pyautogui library.

Start by opening the command prompt and enter the following:

pip install pyautogui 

After it finishes downloading we are ready to begin!

Importing the library


As with any new library we want to use in our project we must start by importing the library at the top of our file.

import pyautogui as p

For this project I abbreviated the library as p, but you may choose whatever abbreviate for the library you would like.

Moving the mouse


To move the mouse around the screen use the moveTo() method.


import pyautogui as p
p.moveTo(50, 50, 1)


The moveTo() command takes three arguments. The first and second being the x and y value that the mouse will move to on the screen, and the last the duration or time it will take for the mouse pointer to move to that location.


Clicking the mouse


Once we move the mouse pointer to the correct location we need to be able to click the mouse.


import pyautogui as p
p.moveTo(50, 50, 1)
p.click()


Here are all the arguments the click method can take

pyautogui.click(x=moveToX, y=moveToY, clicks=num_of_clicks, interval=secs_between_clicks, button='left')


Here are other related methods

p.rightClick(x=moveToX, y=moveToY)
p.middleClick(x=moveToX, y=moveToY)
p.doubleClick(x=moveToX, y=moveToY)
p.tripleClick(x=moveToX, y=moveToY)

Setting the number of clicks

By giving values to the clicks and interval arguments, we can specify how many clicks we want and how fast we want them. Depending on the response time of the button you want to click you may have to increase the interval time between each click.


import pyautogui as p
p.moveTo(50, 50, 1)
p.click(clicks = 100, interval = 0.1)



Finding your button without knowing the position


import pyautogui as p
p.moveTo(p.locateCenterOnScreen('image.png'), duration = 1)
p.click(clicks = 100, interval = 0.1)


The second line looks a bit complex so let's break it down into parts

 pyautogui.locateCenterOnScreen('looksLikeThis.png')