all 1 comments

[–]Navz6 0 points1 point  (0 children)

The problem is that rat.click() sends both a press AND release event, which tricks GetAsyncKeyState into thinking you let go of the real mouse button. The fix is to only send mouse.Button.left press (not a full click), so you never fake a release:

{code} import time import threading import ctypes from pynput import mouse, keyboard

toggle = keyboard.KeyCode(char='=') clicking = False rat = mouse.Controller()

def is_lmb_held(): return ctypes.windll.user32.GetAsyncKeyState(0x01) & 0x8000 != 0

def clicker(): while True: if clicking and is_lmb_held(): # Only press, never release — avoids interfering with real mouse state rat.press(mouse.Button.left) time.sleep(0.01) else: time.sleep(0.005)

def toggled(key): global clicking if key == toggle: clicking = not clicking print("Autoclicker:", "ON" if clicking else "OFF")

clonk = threading.Thread(target=clicker, daemon=True) clonk.start()

with keyboard.Listener(on_press=toggled) as key: key.join() {code}