Application Focus and Termination

Recommended Posts

Xanatopia 0

Xanatopia 0

I've encountered an issue in an application where I have AutoIt execute File -> Exit off of the app menu and then attempt to select a "Yes" button in an exit dialog box to terminate the client app. Unfortunately, running the script doesn't seem to work UNTIL I actually manually select the Application itself using the mouse. Once I click on the app with the mouse the AutoIt script seems to execute properly. I'm guessing that for one reason or another the AutoIt focus isn't on the application itself and that clicking on the application manually sufficiently changes focus for the AutoIt script to finally execute. I've given the AutoIt script sufficient time to run without manually clicking on the App, but no go. The manual step seems to be necessary.

Is there something fundamental that I'm missing here in terms of insuring proper AutoIt focus before attempting to manipulate the components of a given running app? Is there a specific AutoIt function that I should be using to insure that an application window is in focus before executing any components of that app?

Share this post

Link to post

Share on other sites

Xanatopia 0

Xanatopia 0

If you know what the application title is, you can use WinSetOnTop("title", "text") to set it on top so you don't have to manually focus the window.

Hi.

Thank you for the advice. I gave the WinSetOnTop function a try, but interestingly enough the Application Window doesn't actually enter it's OnTop state UNTIL I click on the application manually. I also tried using the WinActive function to try to put focus on the application window, but this doesn't seem to have any effect either.

Any other thoughts on what might be causing this or other options I should try?

Share this post

Link to post

Share on other sites

Xanatopia 0

Xanatopia 0

Okay, I figured it out. The primary problem is that I had an existing WinWaitActive line at the top of my script that was restraining the shift in focus. Once I removed this line and used WinActivate I was able to get access to the appropriate windows without issue.

Thank you very much to everyone who responded, you've assisted me greatly! :-)