Sign in to follow this  
Followers 0
Xanatopia

Application Focus and Termination

6 posts in this topic

Hi all.

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?

Any help is greatly appreciated.

Thanks.

-- Jeff

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

Also remember that AutoIt is just simulating your input, if you were to do it and it wouldn't work, then it won't work when the script does it.


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites

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?

Thanks.

-- Jeff

Share this post


Link to post
Share on other sites

Look up the SetForegroundWindow API call in the User32 dll.


[center][/center]Working on the next big thing.Currently Playing: Halo 4, League of LegendsXBL GT: iRememberYhslaw

Share this post


Link to post
Share on other sites

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! :-)

-- Jeffrey Nuremburg

Share this post


Link to post
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
Sign in to follow this  
Followers 0