0

I am trying to make an auto clicker controlled with keyboard . And I get

Exception in thread thread-2

indeed I get

TypeError: clickc() argument after * must be an iterable, not bool

import keyboard, pyautogui as pag 
import time
import threading 

number = 9999999999999999999999999999999999999999999999999999999999999999999999999999999

fk = False

def clickc(fk):
    if fk == True:
        pag.click(button="left", clicks=5, interval=1)
    else: 
        return None


def keycontrol(x, shutdown):
    try: 
        if keyboard.is_pressed(x):
            return True
        if keyboard.is_pressed(shutdown):
            return False
    except: 
        pass

p1 = threading.Thread(target=keycontrol, args=("f","v"))

p0 = threading.Thread(target=clickc, args=fk)

fk = p1.start()
p0.start()

Here is the full error :

Exception in thread Thread-2:
Traceback (most recent call last):
  File "C:\Users\muham\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 932, in _bootstrap_inner
    self.run()
  File "C:\Users\muham\AppData\Local\Programs\Python\Python38-32\lib\threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
TypeError: clickc() argument after * must be an iterable, not bool
[Finished in 0.4s]
Cloaaker
  • 60
  • 9

1 Answers1

0

Your 'p0' args should be an iterable (a tuple, list, etc) like the 'p1':

p0 = threading.Thread(target=clickc, args=(fk,))
smassey
  • 5,875
  • 24
  • 37
  • it worked but now my program starts and ends up instantly – Cloaaker May 21 '20 at 14:21
  • Well yes, the use of threads here may obfuscate a bit the fact that you're simply calling 2 functions and exiting. You'll need a main/control loop somewhere to wait for input and react on that input. There's no control loop here and neither of the threads is "blocking" while waiting for input. For more pointers I'd need to know exactly what you're trying to accomplish :) – smassey May 21 '20 at 14:50
  • can you share the exact code if its not problem for you ? I am really dumb at this threading thing . I got the think you are talking about . I tried while True: p1.start() but I got RuntimeError : Threads can only be started once – Cloaaker May 21 '20 at 19:03
  • Maybe your "while True: ..." should be inside your thread, and not the parent of the thread, that is, the thread itself is the control loop. Or maybe you don't need threading at all (and I'm guessing this is the case tbh) but I'd need to know more about what you're actually trying to achieve to propose something better, the snippet posted just isn't enough and I'd need to guess. Cheers – smassey May 21 '20 at 19:34
  • I am reading data with keycontrol . if pressed key is " f " it runs clickc function which it need for auto clicking . And It is endless ( not endless there is a given number in the code named as number ) . If dont hit "v" key the clickc function is not gonna stop . If I want to stop this function by hittin "v" key My program cant wait to end clickc() function. So I need to read real-time data . I tought thats why I need multi threading – Cloaaker May 21 '20 at 20:00