Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.28 KB | None | 0 0
  1. import tkinter as tk
  2. import time
  3. from pynput.mouse import Button, Controller
  4. from pynput.keyboard import Listener, KeyCode
  5. import threading
  6.  
  7. klik = tk.Tk()
  8. menubar = tk.Menu(klik)
  9. klik.title("Klikacz")
  10.  
  11.  
  12. def close():
  13.     exit()
  14.  
  15. def pomoc():
  16.     okno = tk.Tk()
  17.     okno.title("Pomoc")
  18.     okienko = tk.Label(okno, text="Program stworzony do projektu #roadto15k na vikop peel", font=16)
  19.     okienko.pack()
  20. def autoklik():
  21.     delay = 0.01
  22.     button = Button.left
  23.     start_stop_key = KeyCode(char='s')
  24.     exit_key = KeyCode(char='x')
  25.  
  26.  
  27.     class ClickMouse(threading.Thread):
  28.         def __init__(self, delay, button):
  29.             super().__init__()
  30.             self.delay = delay
  31.             self.button = button
  32.             self.running = False
  33.             self.program_running = True
  34.  
  35.         def start_clicking(self):
  36.             self.running = True
  37.  
  38.         def stop_clicking(self):
  39.             self.running = False
  40.  
  41.         def exit(self):
  42.             self.stop_clicking()
  43.             self.program_running = False
  44.  
  45.         def run(self):
  46.             while self.program_running:
  47.                 while self.running:
  48.                     mouse.click(self.button)
  49.                     time.sleep(self.delay)
  50.                 time.sleep(0.1)
  51.  
  52.  
  53.     mouse = Controller()
  54.     click_thread = ClickMouse(delay, button)
  55.     click_thread.start()
  56.  
  57.  
  58.     def on_press(key):
  59.         if key == start_stop_key:
  60.             if click_thread.running:
  61.                 click_thread.stop_clicking()
  62.             else:
  63.                 click_thread.start_clicking()
  64.         elif key == exit_key:
  65.             click_thread.exit()
  66.             listener.stop()
  67.  
  68.     with Listener(on_press=on_press) as listener:
  69.         listener.join()
  70.  
  71.  
  72. klik.config(menu=menubar)
  73. b = tk.Button(klik, text="Start", width=50, height=10, command=autoklik)
  74. b.pack()
  75.  
  76. klikmenu = tk.Menu(menubar, tearoff=0)
  77. menubar.add_cascade(label="Plik", menu=klikmenu)
  78. klikmenu.add_command(label="Pomoc", command=pomoc)
  79. klikmenu.add_separator()
  80. klikmenu.add_command(label="Wyjdź", command=close)
  81.  
  82. labell = tk.Label(klik, text="Po naciśnięciu \"Start\" wciśnij klawisz \"s\" aby rozpocząć")
  83. label = tk.Label(klik, text="Wciśnij \"x\" żeby zatrzymać program")
  84. labell.pack()
  85. label.pack()
  86.  
  87.  
  88. klik.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement