vendredi 19 février 2021

How can I skip an if-statement in python?

I'm still a bloody newbie, don't be angry if I make some very dumb mistakes :) So, I wanted to code an Auto clicker. When you start the program, a little window appears where I can enter the delay between each click. Next, I press "start bot", then, the program waits for me to press 'g' once, when I press 'g', the autoclicker starts to click the right mouse button until I press '0'. Then, I wanted to add an feature, that allows the auto clicker to press the left mouse button if I press 'b'. I tried something with else and continue but that obvisouly didn't work, LOL. Here's my (probably very dumb) code:

import time, pyautogui, keyboard, threading
from tkinter import *
pyautogui.PAUSE = 0.01
window = Tk()

window.title("Autoclickeer")

#Functions
def clickedStart():
    while True:
        print("press 'g' to activate")
        if keyboard.is_pressed('g'):
            time.sleep(3)
            run = True
            interval = None

            try:
                interval = float(txt.get())
            except:
                pass

            start = time.time()

            while run == True:
                if keyboard.is_pressed('0'):
                    run = False
                    break

                if interval != None:
                    if time.time() >= (start + interval):
                        pyautogui.click(button='right')
                        start = time.time()
                else:
                    pyautogui.click(button='right')

        else:
            continue
        print("Press 'b' to activate")
        if keyboard.is_pressed('b'):
            time.sleep(3)
            run = True
            interval = None

            try:
                interval = float(txt.get())
            except:
                pass

            start = time.time()

            while run == True:
                if keyboard.is_pressed('0'):
                    run = False
                    break

                if interval != None:
                    if time.time() >= (start + interval):
                        pyautogui.click(button='left')
                        start = time.time()
                else:
                    pyautogui.click(button='left')




lbl = Label(window, text="Enter delay between each click in seconds")
lbl.grid(column=1, row=0, padx=(75,10))

txt = Entry(window, width=10)
txt.grid(column=1, row=1, padx=(75, 10))

btn = Button(window, text="Start Bot", command=clickedStart, bg="green", fg="Lightgreen")
btn.grid(column=1, row=2, padx=(75, 10), pady=(15,10))

window.geometry("258x100")

window.mainloop()

So, how do I do that?

Aucun commentaire:

Enregistrer un commentaire