Simple Autoclicker
In this tutorial, we will be using Python to create a simple autoclicker program, or a program that clicks (the mouse) for us.
Installing The Needed Modules/Libraries
In order for us to create our autoclicker, we'll need to install a couple of Python libraries using pip
. To do so, you can open your command prompt/terminal and type the following commands:
pip install pyautogui
pip install keyboard
If the commands don't work for you, go here.
Using The Modules
Now, let's discuss how our program will work. We've already installed the required modules, so, how will they work in our program?
Well, the keyboard
modules is used for methods in the keyboard. We're using it for detecting key presses so when the user holds a specific key, the program will now and it will boot the autoclicker and start clicking.
The pyautogui
module is used for automation, such as clicking, typing, and moving the mouse. We'll be using pyautogui
for clicking the mouse.
Implementation
Below is the implementation of the autoclicker:
import pyautogui
import keyboard
key = input("Auto Clicker Key Bind: ")
button = input("Which Button? 'primary' For The Left Button And 'right' For The Right Button. ")
while True:
if keyboard.is_pressed(key):
pyautogui.click(button=button)
Code Result
When you run the code, the program will prompt you for a key bind, or a key that you hold in order for the code to click. Then, it asks you for which button to click, left or right.
Try typing "c
" as the key bind and type "primary
as the button, and then hold the c
key on your keyboard. You'll notice that the mouse is clicking!
Code Breakdown
The program is actually very simple. We use a while
loop for the main code and check if the user is holding the key bind key. If they are, we are going to click the mouse. Since we have a while
loop, the code will run infinitely, so we are able to hold the c
key and have the code click!
Extensions
Fun extension ideas:
- Allow the user to press a key to start the code and press that key again to release the key, so they don't need to hold the key.
- Allow the code to thread itself, or create multiple instances of itself to achieve a higher CPS.