Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. import time
  2. import threading
  3. from pynput.mouse import Button, Controller
  4. from pynput.keyboard import Listener, KeyCode
  5.  
  6.  
  7. delay = 0.3
  8. button = Button.left
  9. start_stop_key = KeyCode(char='o')
  10. exit_key = KeyCode(char='p')
  11.  
  12.  
  13. class ClickMouse(threading.Thread):
  14.     def __init__(self, delay, button):
  15.         super(ClickMouse, self).__init__()
  16.         self.delay = delay
  17.         self.button = button
  18.         self.running = False
  19.         self.program_running = True
  20.  
  21.     def start_clicking(self):
  22.         self.running = True
  23.  
  24.     def stop_clicking(self):
  25.         self.running = False
  26.  
  27.     def exit(self):
  28.         self.stop_clicking()
  29.         self.program_running = False
  30.  
  31.     def run(self):
  32.         while self.program_running:
  33.             while self.running:
  34.                 mouse.click(self.button)
  35.                 time.sleep(self.delay)
  36.             time.sleep(0.1)
  37.  
  38.  
  39. mouse = Controller()
  40. click_thread = ClickMouse(delay, button)
  41. click_thread.start()
  42.  
  43.  
  44. def on_press(key):
  45.     if key == start_stop_key:
  46.         if click_thread.running:
  47.             click_thread.stop_clicking()
  48.         else:
  49.             click_thread.start_clicking()
  50.     elif key == exit_key:
  51.         click_thread.exit()
  52.         listener.stop()
  53.  
  54.  
  55. with Listener(on_press=on_press) as listener:
  56.     listener.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement