Hello Stack Overflow users, I am wondering how to fix my Python Auto Clicker. This is Python 3.9.7 and I am using the program Visual Studio Code from Visual Studio Code and when I change my delay
variable it stays clicking at the same speed. I am using pynput importing to check if key is pressed and to get the mouse with pynput.keyboard
and pynput.mouse
I also import the mouse with from pynput import mouse
. Is their anyway to make my own waiting script kinda like time.sleep(float)
well anyways lets get to the point. Here is the code:
###################
## Python Script Made by: Ryans World
## Python Script Based off of: PyTutorials on YouTube
## Python Version: 3.9.7
## Recommended Versions: 3.10 or 3.9.7
###################
# Imports
import threading
import time
from pynput import mouse
from pynput.mouse import Button, Controller
from pynput.keyboard import Key, Listener
# Variables
delay = 0.01
button = Button.left
# Functions
class ClickMouse(threading.Thread):
def __init__(self, delay, button):
super().__init__()
self.delay = delay
self.button = button
self.running = False
self.program_running = True
# Run the script;returns True
def start_clicking(self):
self.running = True
# Stop the script;returns False
def stop_clicking(self):
self.running = False
# Exit the program;breaks the script
def exit(self):
self.stop_clicking()
self.program_running = False
# Runs the AutoClicking
def run(self):
while self.program_running:
while self.running:
mouse.click(self.button)
time.sleep(self.delay)
# Thread & Mouse
mouse = Controller()
click_thread = ClickMouse(delay, button)
click_thread.start()
# Checks if USER pressed key to run program
def on_press(key):
if key == Key.alt_l:
if click_thread.running:
click_thread.stop_clicking()
else:
click_thread.start_clicking()
elif key == Key.esc:
click_thread.exit()
listener.stop() # Shuts down program completely
# Joins the Program with the 'on_press' function
with Listener(on_press=on_press) as listener:
listener.join()