KoreMike
KoreMike

Reputation: 91

Any way to speed up WinWaitNotActive?

I have an auto-send script which works in 2 steps:

  1. It runs a target program, and begins a database update command within the program.
  2. After WinWaitNotActive (ie database update is finished) it then runs a second 'search' command in the target program

This is working ok, but it is too slow - up to 10-15 seconds after the db update. Is there a way to speed up WinWaitNotActive? Instead of WinWait I tried using Sleep for 8 seconds, but sometimes the second command ran before the db update had finished.

Is it possible to monitor the process activity, and run the second command once it drops below a certain level?

Here is the code:

send !w::
Run "Target"
/'Update Command'
WinWaitNotActive, Target, , ,
Run "Target"
/'Search Command' "Search Term"
return

Upvotes: 2

Views: 386

Answers (1)

NbdNnm
NbdNnm

Reputation: 528

You can use SetTimer with your desired interval to check the window status.

Run "Target"
; /'Update Command'
SetTimer, CheckWindow, -200  ; this check the window every 200 milliseconds
return

CheckWindow:
    if WinActive, Target
        return
    Run "Target"
    ; /'Search Command' "Search Term"
    SetTimer, % A_ThisLabel, Off      ; stop the timer
Return

Upvotes: 1

Related Questions