1515import pyautogui
1616from PIL import ImageGrab , Image
1717from pynput import mouse
18+ import ctypes
1819
1920# Performance settings
2021try :
2122 pydirectinput .PAUSE = 0
2223 pyautogui .PAUSE = 0
24+ pydirectinput .FAILSAFE = False
25+ pyautogui .FAILSAFE = False
2326except Exception :
2427 pass
2528
29+ # Set Windows timer resolution to 1ms for high-precision timing
30+ if os .name == 'nt' :
31+ try :
32+ ctypes .windll .winmm .timeBeginPeriod (1 )
33+ except Exception :
34+ pass
35+
2636def resource_path (relative_path ):
2737 """Get absolute path to resource, works for dev and PyInstaller."""
2838 try :
@@ -503,9 +513,14 @@ def _run_loop(self):
503513 self .running = False
504514 break
505515
506- self .after (0 , lambda r = row : r .set_completed ())
507- time .sleep (delay )
508- self .after (0 , lambda r = row : r .set_active (False ))
516+ if delay > 0.05 :
517+ self .after (0 , lambda r = row : r .set_completed ())
518+
519+ if delay > 0 :
520+ time .sleep (delay )
521+
522+ if delay > 0.05 :
523+ self .after (0 , lambda r = row : r .set_active (False ))
509524 finally :
510525 if mode == "limited" and loop > reps :
511526 self .after (0 , lambda : self .status_label .configure (text = "✓ Completed" , text_color = COLORS ["success" ]))
@@ -533,7 +548,6 @@ def _perform_action(self, key, hold_time):
533548 if cmd in {'click' , 'rclick' , 'mclick' }:
534549 x , y = map (int , args )
535550 pydirectinput .moveTo (x , y )
536- time .sleep (0.05 )
537551 button = {'click' : 'left' , 'rclick' : 'right' , 'mclick' : 'middle' }[cmd ]
538552 if hold_time > 0 :
539553 pydirectinput .mouseDown (button = button )
@@ -545,7 +559,7 @@ def _perform_action(self, key, hold_time):
545559
546560 elif cmd == 'moveto' :
547561 x , y = map (int , args )
548- pyautogui .moveTo (x , y , duration = 0.3 )
562+ pyautogui .moveTo (x , y )
549563 return True
550564
551565 elif cmd == 'waitcolor' :
@@ -582,7 +596,7 @@ def _perform_action(self, key, hold_time):
582596 else :
583597 pydirectinput .press (key )
584598 else :
585- pyautogui .write (key , interval = 0.05 )
599+ pyautogui .write (key , interval = 0.0 )
586600
587601 return True
588602 except Exception as e :
0 commit comments