Jump to content

Single or multiple scripts to monitor windows


Recommended Posts

Hello again,

I'm planning to have multiple scripts running simultaneously. Each basically does the same thing, waiting for the exact window handle to active and enters the loop, and if the window does not exist the program quits.

Example:

while WinExists($WinHandle)
    Sleep(128)
    if WinGetHandle("[ACTIVE]") = $WinHandle then Do()
    Sleep(128)
WEnd
exit

If I have 7 scripts like this running, it means 7 times of WinExists and WinGetHandle in a loop. I believe WinExists works by getting all the windows and compare them. Perhaps, WinGetHandle also. So, I assume too much can be not good.

I thought maybe only one script that detect for active window would be lighter for the CPU.

Something like this, maybe:

$x = 0
While 1
    $ActiveWin=WingetHandle("[Active]");Get active win
    For $i=1 to $WinList[0] ;Compare with the list
        if $WinList[$i] = $ActiveWin then Do($i)
    Next
    $x+=1;indicator for WinExists to check consecutive win
    If not winExists($WinList[$x]) then RemoveFromList($x);If not exists remove from list
    if $x >= $WinList[0] then $x = 0;Reset the indicator
Wend

Which one is better, using multiple scripts to monitor multiple windows, or using one script that monitors multiple windows? In terms of CPU usage.

Thank you.

Link to comment
Share on other sites

In my opinion one script is always better than multiple. For CPU yes, but also for communications. Right now you may not need these scripts to pass information, but there may come a day when you have this need, it's very difficult in multiple scripts and very simple in multiple functions.

Link to comment
Share on other sites

In my opinion one script is always better than multiple. For CPU yes, but also for communications. Right now you may not need these scripts to pass information, but there may come a day when you have this need, it's very difficult in multiple scripts and very simple in multiple functions.

Probably also alot easier to edit single script rather than multiples of similar script..

I see, I guess one script it is. The problem with one big script if the usage are varies is that we cannot re-declare constant variables. Like this case, even though the entry point is to get active window, the usage are varies for each window. I had some problems with that, so I had to "comment" on the variables in the UDFs. Probably they were betas. Not a biggie though.

Thanks for the suggestion and thoughts, guys.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...