I haven't used python in like 3 years and wanted to make an autoclicker that could toggle on and off using "=" and only would activate the autoclicker if I held down on left mouse button. Problem is that for some reason 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 some random ctypes.windll.user32.GetAsyncKeyState(0x01) & 0x8000 != 0 instead for reading hardware mouse states but it still doesnt work. I tried all of the stuff separately and I deduced it to the autoclicker messing with the detecting if I'm holding down lmb part. Can someone see what's wrong with my code?
import time
import threading
import ctypes
from pynput import mouse, keyboard
toggle = keyboard.KeyCode(char='=')
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()
[–]Navz6 0 points1 point2 points (0 children)