Two main problems... First for your point a) you should just use WinWait
instead and then you can use WinActivate
to set it as the active one. After WinActivate
you don't need to use WinWaitActive
- you can check its return code instead.
Second for point b) you need to behave kind of the same way. You can (with absolute care) use BlockInput(True)
before you start activating your Window and then sending some keystrokes, etc to prevent the user from "stealing" the Window Focus. And after you are finished, you should immediately use BlockInput(False)
. However, it might still occur, that some other application pops up and becomes the active window... For this, you might check for your active window always before perfoming something with it... But it's much better for such cases to try to use the Control...
functions because they don't depend on the window to be the active one...
And finally, you should just once determine your windows handle ($handle = WinExists("Vision")
) at the topmost possibility and then just use its handle for further usage of Win...
functions like WinGetTitle($handle)
. Because especially when you open popup windows within your application, they might have the same word in its title. So it might not be sure that your commands are being executed with the window you suppose them to be. After getting the PID of your newly run window you might consider using it to receive its windows handle - there are functions in the AutoIt forums to receive a handle from a PID. So you can be sure to use the exact window you are supposing to use.
Oh - and the usage of control IDs is really bad. Who can assure you, they won't change? Use some control names instead... see the section about "extended control title definition" or so in the documentation for these possibilities...