Untitled
import pyautogui import keyboard import time import threading def interrupt_script(): print("Interrupção detectada. Finalizando o script...") exit() def monitor_interrupt(): while True: if keyboard.is_pressed('esc'): interrupt_script() time.sleep(0.1) # Evita que o loop consuma muito processamento interrupt_thread = threading.Thread(target=monitor_interrupt) interrupt_thread.daemon = True # O thread será finalizado quando o programa principal for encerrado interrupt_thread.start() try: while True: # Simula ações com pyautogui pyautogui.moveTo(1228, 334, duration=1) for i in range(500): pyautogui.click() pyautogui.click() time.sleep(1) except KeyboardInterrupt: print("Script interrompido manualmente.")
Leave a Comment