You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. import psutil
  2. import pyautogui as send_input
  3. import subprocess
  4. import os
  5. CLICKER_PATH = os.path.expandvars(r"%local_repo%\other\toggler\clicker.exe")
  6. CLICKER_START_COM = [CLICKER_PATH,'20']
  7. class clicker_manager:
  8. def __init__(self):
  9. self.proc_id = None
  10. for process in psutil.process_iter():
  11. if process.name() == 'clickerP.exe':
  12. self.proc_id = process.pid
  13. break
  14. print(self.proc_id)
  15. if self.proc_id is None:
  16. self.proc_id = subprocess.Popen(CLICKER_START_COM).pid
  17. self.on = False
  18. def toggle(self):
  19. send_input.press('tab')
  20. self.on = not self.on
  21. def turn_off(self):
  22. if self.on:
  23. self.toggle()
  24. def turn_on(self):
  25. if not self.on:
  26. self.toggle()
  27. def kill(self):
  28. try:
  29. proc = psutil.Process(self.proc_id)
  30. for sub_proc in proc.children(recursive=True):
  31. sub_proc.kill()
  32. proc.kill()
  33. except psutil.NoSuchProcess:
  34. pass
  35. def update(self):
  36. self.on = os.path.exists(os.path.join(os.path.dirname(CLICKER_PATH),'on'))
  37. if __name__ == "__main__":
  38. test = clicker_manager()