Initial Project: Troubles with Non-functional Auto-Clicker Code

To avoid repetition, you should extract the logic of the button click handler and create a separate function. Instead of emulating the click event, you can then run this function using a timer. Additionally, it is recommended to bind the handler using addEventListener rather than onclick attribute, as it provides a better way of handling events.
I am attempting to create a basic auto clicker using python3 pyautogui. It allows users to select the coordinates for the clicking location. However, when I run the code, I encounter error messages despite there being no apparent issues. I have only just started coding yesterday.


I’m encountering difficulties understanding why my code isn’t working when I attempt to create an autoclicker using pynput as my initial project. The purpose of the code is to initiate or terminate clicking whenever I press “ctrl+alt+i” and perform a single click every second. Below is my current code. Although I don’t fully comprehend why it doesn’t function, I have managed to make the “click_thread.running” change from true to
false, python
when listening to my keyboard, which enables the clicking to work. However, it only operates when I set “self.running” to true in the “ClickMouse” class. Although the output of printing “click_thread.running” appears to switch from true to false, I’m unsure why the clicking does not commence. I suspect this may be due to it being a subclass of “threading.Thread” or a potential error in my class implementation. Regardless, I have been working on this for a few days and I’m currently stuck, seeking assistance to resolve the issue. Any help would be greatly appreciated!

import time
import threading
from pynput.mouse import Button, Controller
from pynput import keyboard
delay = 1
button = Button.left
class ClickMouse(threading.Thread):
    def __init__(self, delay, button):
        self.delay = delay
        self.button = button                
        self.running = False             
    def run(self):
        while self.running == True:
    def start_clicking(self):
        self.running = True
    def stop_clicking(self):
        self.running = False
mouse = Controller()
click_thread = ClickMouse(delay, button)
def on_activate_i():
    print('++i pressed')
    if click_thread.running == False:   
with keyboard.GlobalHotKeys({'++i': on_activate_i,}) as h:


When you make a call to


, the handler associated with


will invoke your


function on a separate thread. Consequently,


will be


. Consequently, your while loop will terminate immediately, bringing an end to the thread.



the default and delay creating the thread until



Where are you clicking? At random?

Frequently Asked Questions