I need help implamenting something to this code. I wanted to when I toggle off the auto presser it presses escape one time. I know it’s probably a mess I had chat GPT write it because I don’t know how. /u/TwitchNotTTv Python Education

import threading

import time

import keyboard

from pynput.keyboard import Controller

import tkinter as tk

from tkinter import messagebox

class AutoClickerApp:

def __init__(self):

self.root = tk.Tk()

self.root.title(“Auto Clicker”)

self.controller = Controller()

self.target_key = None

self.auto_clicking = False # State of auto-clicking

self.speed = 10 # Clicks per second

self.lock = threading.Lock()

self.setup_ui()

def setup_ui(self):

tk.Label(self.root, text=”Key to Auto-Press:”).grid(row=0, column=0, pady=5, padx=5)

self.key_entry = tk.Entry(self.root)

self.key_entry.grid(row=0, column=1, pady=5, padx=5)

tk.Button(self.root, text=”Set Key”, command=self.set_key).grid(row=0, column=2, pady=5, padx=5)

tk.Label(self.root, text=”Press Speed (CPS):”).grid(row=1, column=0, pady=5, padx=5)

self.speed_entry = tk.Entry(self.root)

self.speed_entry.insert(0, “10”)

self.speed_entry.grid(row=1, column=1, pady=5, padx=5)

tk.Button(self.root, text=”Set Speed”, command=self.set_speed).grid(row=1, column=2, pady=5, padx=5)

tk.Label(self.root, text=”Press your bound key to toggle auto-clicking.”).grid(row=2, column=0, columnspan=3, pady=10)

def set_key(self):

key = self.key_entry.get().strip()

if key:

self.target_key = key

messagebox.showinfo(“Key Set”, f”Target key set to: {key}”)

else:

messagebox.showwarning(“Error”, “Please enter a valid key.”)

def set_speed(self):

try:

speed = int(self.speed_entry.get())

if speed > 0:

self.speed = speed

else:

messagebox.showwarning(“Error”, “Please enter a positive number.”)

except ValueError:

messagebox.showwarning(“Error”, “Please enter a valid number.”)

def toggle_clicking(self):

“””Toggle the auto-clicking state.”””

with self.lock:

self.auto_clicking = not self.auto_clicking

if self.auto_clicking:

print(“Auto-clicking started.”)

threading.Thread(target=self.auto_click, daemon=True).start()

else:

print(“Auto-clicking stopped.”)

def listener(self):

“””Listen for the toggle key to start/stop auto-clicking.”””

while True:

if self.target_key:

if keyboard.is_pressed(self.target_key):

# Wait for the key release to toggle the state

self.toggle_clicking()

while keyboard.is_pressed(self.target_key): # Avoid retriggering

time.sleep(0.01)

time.sleep(0.01)

def auto_click(self):

“””Simulate the key ‘y’ being pressed repeatedly.”””

while True:

with self.lock:

if not self.auto_clicking:

break

self.controller.press(‘y’) # Always press ‘y’

self.controller.release(‘y’)

time.sleep(1 / self.speed)

def run(self):

threading.Thread(target=self.listener, daemon=True).start()

self.root.mainloop()

if __name__ == “__main__”:

app = AutoClickerApp()

app.run()

submitted by /u/TwitchNotTTv
[link] [comments]

​r/learnpython import threading import time import keyboard from pynput.keyboard import Controller import tkinter as tk from tkinter import messagebox class AutoClickerApp: def __init__(self): self.root = tk.Tk() self.root.title(“Auto Clicker”) self.controller = Controller() self.target_key = None self.auto_clicking = False # State of auto-clicking self.speed = 10 # Clicks per second self.lock = threading.Lock() self.setup_ui() def setup_ui(self): tk.Label(self.root, text=”Key to Auto-Press:”).grid(row=0, column=0, pady=5, padx=5) self.key_entry = tk.Entry(self.root) self.key_entry.grid(row=0, column=1, pady=5, padx=5) tk.Button(self.root, text=”Set Key”, command=self.set_key).grid(row=0, column=2, pady=5, padx=5) tk.Label(self.root, text=”Press Speed (CPS):”).grid(row=1, column=0, pady=5, padx=5) self.speed_entry = tk.Entry(self.root) self.speed_entry.insert(0, “10”) self.speed_entry.grid(row=1, column=1, pady=5, padx=5) tk.Button(self.root, text=”Set Speed”, command=self.set_speed).grid(row=1, column=2, pady=5, padx=5) tk.Label(self.root, text=”Press your bound key to toggle auto-clicking.”).grid(row=2, column=0, columnspan=3, pady=10) def set_key(self): key = self.key_entry.get().strip() if key: self.target_key = key messagebox.showinfo(“Key Set”, f”Target key set to: {key}”) else: messagebox.showwarning(“Error”, “Please enter a valid key.”) def set_speed(self): try: speed = int(self.speed_entry.get()) if speed > 0: self.speed = speed else: messagebox.showwarning(“Error”, “Please enter a positive number.”) except ValueError: messagebox.showwarning(“Error”, “Please enter a valid number.”) def toggle_clicking(self): “””Toggle the auto-clicking state.””” with self.lock: self.auto_clicking = not self.auto_clicking if self.auto_clicking: print(“Auto-clicking started.”) threading.Thread(target=self.auto_click, daemon=True).start() else: print(“Auto-clicking stopped.”) def listener(self): “””Listen for the toggle key to start/stop auto-clicking.””” while True: if self.target_key: if keyboard.is_pressed(self.target_key): # Wait for the key release to toggle the state self.toggle_clicking() while keyboard.is_pressed(self.target_key): # Avoid retriggering time.sleep(0.01) time.sleep(0.01) def auto_click(self): “””Simulate the key ‘y’ being pressed repeatedly.””” while True: with self.lock: if not self.auto_clicking: break self.controller.press(‘y’) # Always press ‘y’ self.controller.release(‘y’) time.sleep(1 / self.speed) def run(self): threading.Thread(target=self.listener, daemon=True).start() self.root.mainloop() if __name__ == “__main__”: app = AutoClickerApp() app.run() submitted by /u/TwitchNotTTv [link] [comments] 

import threading

import time

import keyboard

from pynput.keyboard import Controller

import tkinter as tk

from tkinter import messagebox

class AutoClickerApp:

def __init__(self):

self.root = tk.Tk()

self.root.title(“Auto Clicker”)

self.controller = Controller()

self.target_key = None

self.auto_clicking = False # State of auto-clicking

self.speed = 10 # Clicks per second

self.lock = threading.Lock()

self.setup_ui()

def setup_ui(self):

tk.Label(self.root, text=”Key to Auto-Press:”).grid(row=0, column=0, pady=5, padx=5)

self.key_entry = tk.Entry(self.root)

self.key_entry.grid(row=0, column=1, pady=5, padx=5)

tk.Button(self.root, text=”Set Key”, command=self.set_key).grid(row=0, column=2, pady=5, padx=5)

tk.Label(self.root, text=”Press Speed (CPS):”).grid(row=1, column=0, pady=5, padx=5)

self.speed_entry = tk.Entry(self.root)

self.speed_entry.insert(0, “10”)

self.speed_entry.grid(row=1, column=1, pady=5, padx=5)

tk.Button(self.root, text=”Set Speed”, command=self.set_speed).grid(row=1, column=2, pady=5, padx=5)

tk.Label(self.root, text=”Press your bound key to toggle auto-clicking.”).grid(row=2, column=0, columnspan=3, pady=10)

def set_key(self):

key = self.key_entry.get().strip()

if key:

self.target_key = key

messagebox.showinfo(“Key Set”, f”Target key set to: {key}”)

else:

messagebox.showwarning(“Error”, “Please enter a valid key.”)

def set_speed(self):

try:

speed = int(self.speed_entry.get())

if speed > 0:

self.speed = speed

else:

messagebox.showwarning(“Error”, “Please enter a positive number.”)

except ValueError:

messagebox.showwarning(“Error”, “Please enter a valid number.”)

def toggle_clicking(self):

“””Toggle the auto-clicking state.”””

with self.lock:

self.auto_clicking = not self.auto_clicking

if self.auto_clicking:

print(“Auto-clicking started.”)

threading.Thread(target=self.auto_click, daemon=True).start()

else:

print(“Auto-clicking stopped.”)

def listener(self):

“””Listen for the toggle key to start/stop auto-clicking.”””

while True:

if self.target_key:

if keyboard.is_pressed(self.target_key):

# Wait for the key release to toggle the state

self.toggle_clicking()

while keyboard.is_pressed(self.target_key): # Avoid retriggering

time.sleep(0.01)

time.sleep(0.01)

def auto_click(self):

“””Simulate the key ‘y’ being pressed repeatedly.”””

while True:

with self.lock:

if not self.auto_clicking:

break

self.controller.press(‘y’) # Always press ‘y’

self.controller.release(‘y’)

time.sleep(1 / self.speed)

def run(self):

threading.Thread(target=self.listener, daemon=True).start()

self.root.mainloop()

if __name__ == “__main__”:

app = AutoClickerApp()

app.run()

submitted by /u/TwitchNotTTv
[link] [comments] 

Leave a Reply

Your email address will not be published. Required fields are marked *