How can I control an autoclicker without emulated clicks turning it back off?

11 hours ago 1
ARTICLE AD BOX

I want to make an autoclicker that can toggle on and off using = only activates the autoclicker if I hold the left mouse button.

However, the emulated clicks using pynput are being detected as me releasing my actual finger from my mouse, which stops the autoclicker. AI told me not to use pynput for listening and to use ctypes.windll.user32.GetAsyncKeyState(0x01) & 0x8000 != 0 instead for reading hardware mouse states, but it still doesn't work. I tried all of the stuff separately and I deduced it to the autoclicker messing left mouse button detection.

What's wrong with my code?

import time import threading import ctypes from pynput import mouse, keyboard toggle = keyboard.Key.f6 clicking = False rat = mouse.Controller() def clicker(): while True: if clicking == True and ctypes.windll.user32.GetAsyncKeyState(0x01) & 0x8000 != 0: rat.click(mouse.Button.left, 1) time.sleep(0.01) else: time.sleep(0.005) def toggled(key): global clicking if key == toggle: clicking = not clicking print("Autoclicker:", clicking) clonk = threading.Thread(target=clicker, daemon=True) clonk.start() with keyboard.Listener(on_press=toggled) as key: key.join()
Read Entire Article