jeudi 10 décembre 2020

Python random Auto clicker not working (I can't make it random I have no idea why)

I'm a bit new to python and I was trying to make an auto clicker step by step with a tutorial. it worked but when I tried to make it random it didn't worked ):, can someone help me please? thanks for reading. (now Im just typing random things so I can post this thread lol okay I think I typed enough)

The code:

import time
import threading
import random
from pynput.mouse import Button, Controller
from pynput.keyboard import Listener, KeyCode


delay = random.uniform(0.01,1)
button = Button.left
start_stop_key = KeyCode(char='3')
exit_key = KeyCode(char='k')


class ClickMouse(threading.Thread):
    def __init__(self, delay, button):
        super(ClickMouse, self).__init__()
        self.delay = delay
        self.button = button
        self.running = False
        self.program_running = True

    def start_clicking(self):
        self.running = True

    def stop_clicking(self):
        self.running = False

    def exit(self):
        self.stop_clicking()
        self.program_running = False

    def run(self):
        while self.program_running:
            while self.running:                
                mouse.click(self.button)
                time.sleep(self.delay)
                delay = random.uniform(0.01,1)  # <-- This line Isn't working            


mouse = Controller()
click_thread = ClickMouse(delay, button)
click_thread.start()


def on_press(key):
    if key == start_stop_key:
        if click_thread.running:
            click_thread.stop_clicking()
        else:
            click_thread.start_clicking()
    elif key == exit_key:
        click_thread.exit()
        listener.stop()


with Listener(on_press=on_press) as listener:
    listener.join()



Aucun commentaire:

Enregistrer un commentaire