How to make a Python auto clicker?

Creating a Python auto clicker involves using the pyautogui library to simulate mouse clicks at specified intervals. In this tutorial, we'll walk you through the process of building a simple auto clicker using Python. Make sure you have Python installed on your system and install the pyautogui library if you haven't already by running pip install pyautogui.
import pyautogui
import time
import random
# Function to perform auto clicks
def auto_clicker(num_clicks, click_delay):
try:
print("Auto Clicker will start in 3 seconds. Move your mouse to the desired click location.")
time.sleep(3)
for _ in range(num_clicks):
x, y = pyautogui.position() # Get current mouse position
pyautogui.click(x, y) # Perform a mouse click
print(f"Click at ({x}, {y})")
time.sleep(random.uniform(click_delay - 0.1, click_delay + 0.1)) # Add some randomness to the delay
print("Auto Clicker has finished.")
except KeyboardInterrupt:
print("Auto Clicker stopped.")
# Main function
def main():
print("Python Auto Clicker")
print("-------------------")
num_clicks = int(input("Enter the number of clicks: "))
click_delay = float(input("Enter the click delay (in seconds): "))
auto_clicker(num_clicks, click_delay)
if __name__ == "__main__":
main()This code defines a Python auto clicker script that lets you specify the number of clicks and the delay between each click. The script will move the mouse cursor to the current position and simulate mouse clicks.
Here’s how to use the script:
- Save the code above in a Python file, for example,
auto_clicker.py. - Open a terminal and navigate to the directory containing the script.
- Run the script by executing
python auto_clicker.py. - Follow the on-screen instructions to specify the number of clicks and the click delay.
- Move your mouse cursor to the desired click location before the script starts.
- The auto clicker will begin clicking according to your settings. Press Ctrl+C to stop it at any time.
Please use this script responsibly and only for legitimate purposes, as auto clickers can be used unethically in certain contexts.
Buy me a Coffee: https://bmc.link/sarahdev
Access to my private Github: bit.ly/3KDPw6G
(With all the source code from my various projects posted on Medium, you’ll find source code previews and so much more )
