So I was trying to make an auto clicker using Pynput module that could be toggled on or off with a key I don't know exactly why but upon pressing the trigger for turning it on i.e. "c" in this case, it shows a bunch of errors mainly referring to - KeyCode object is not 'callable' and Unhandled exception in listener callback these are the errors
the code goes like this..
import threading
from pynput.mouse import Controller, Button
from pynput.keyboard import Listener, KeyCode
import time
TriggerAutoClicker = KeyCode(char = "c")
AutoClickerstate = False
mouse = Controller()
def autoclick():
while True:
mouse.click(button.left, 1)
time.sleep(0.01)
def toggling(key):
if key == TriggerAutoClicker:
global AutoClickerstate
AutoClickerstate = not AutoClickerstate
click_thread = threading.Thread(target = autoclick)
click_thread.start
with Listener(on_press = TriggerAutoClicker) as listener :
listener.join()
kindly please point out any errors in the above script or provide a better alternative for performing the task