Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- import time
- from pynput.mouse import Button, Controller
- from pynput.keyboard import Listener, KeyCode
- import threading
- klik = tk.Tk()
- menubar = tk.Menu(klik)
- klik.title("Klikacz")
- def close():
- exit()
- def pomoc():
- okno = tk.Tk()
- okno.title("Pomoc")
- okienko = tk.Label(okno, text="Program stworzony do projektu #roadto15k na vikop peel", font=16)
- okienko.pack()
- def autoklik():
- delay = 0.01
- button = Button.left
- start_stop_key = KeyCode(char='s')
- exit_key = KeyCode(char='x')
- class ClickMouse(threading.Thread):
- def __init__(self, delay, button):
- super().__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)
- time.sleep(0.1)
- 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()
- klik.config(menu=menubar)
- b = tk.Button(klik, text="Start", width=50, height=10, command=autoklik)
- b.pack()
- klikmenu = tk.Menu(menubar, tearoff=0)
- menubar.add_cascade(label="Plik", menu=klikmenu)
- klikmenu.add_command(label="Pomoc", command=pomoc)
- klikmenu.add_separator()
- klikmenu.add_command(label="Wyjdź", command=close)
- labell = tk.Label(klik, text="Po naciśnięciu \"Start\" wciśnij klawisz \"s\" aby rozpocząć")
- label = tk.Label(klik, text="Wciśnij \"x\" żeby zatrzymać program")
- labell.pack()
- label.pack()
- klik.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement