W
W
wenzeslaus2021-06-19 13:47:02
Python
wenzeslaus, 2021-06-19 13:47:02

How to make a switch?

and so hello. I decided to make a switch for my autoclicker bot. I wanted that when I wrote "stop" in the terminal, it turned off, and when "go" it turned on. I decided to do it through a while loop and ran into this problem. While the loop is not running, the "stop" command works, but once I start the loop, I can't stop it anymore. How should I write it down so that I could stop it at any time and turn it on again at any time?

import pyautogui,time, keyboard
pyautogui.PAUSE = 0.00001
#time.sleep(5)
key = "alt"
while True:
    pov = False
    trx = input("")
    words = trx.split()
    if words[0] == "stop":
        pov = False
        print("выключено")
    if words[0] == "go":
        pov = True
        print("включено")
        while pov:
            if keyboard.is_pressed(key):
                try:
                    pyautogui.click(clicks=20, interval=0.0001)
                except:
                    print("что-то пошло не так")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
link_vrb, 2021-06-19
@wenzeslaus

you can make two additional threads:
stop - it waits for the cycle to start and starts its work - you can put it at the beginning of the cycle start -
it waits for the bot to finish the work with the stop command and starts working

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question