Sign in to follow this  
Followers 0
palindrome

Ensure target window is active

9 posts in this topic

I have a script that interacts with a window through pixel reads, mouse activity and keyboard activity. Is there a way to easily make sure that the target window is active at every interaction without a lot of cumbersome extra code? Ideally, I want to pause when the target window loses focus and resume when it resumes focus.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

WinWaitActive() ahead of each action

Edit: or if it is always the same window/title - perhaps an adlib function with a WinWaitActive line in it...

Edited by herewasplato

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

I have a script that interacts with a window through pixel reads, mouse activity and keyboard activity. Is there a way to easily make sure that the target window is active at every interaction without a lot of cumbersome extra code? Ideally, I want to pause when the target window loses focus and resume when it resumes focus.

Can you post the affected code?

-John

Share this post


Link to post
Share on other sites

WinWaitActive() ahead of each action

Edit: or if it is always the same window/title - perhaps an adlib function with a WinWaitActive line in it...

The first solution would be quite tedious to code and make the script slower. I'm going to try the second solution. Is there a way to somehow watch for the windows message that says the window is losing focus and IMMEDIATELY react to that? This would be something that adlib functions can't do, since they are run only periodically.

Share this post


Link to post
Share on other sites

Adlib() - ~Jap

Share this post


Link to post
Share on other sites

...make the script slower...

...not so that you would notice with a WinWaitDelay of 0 or 1 via the Opt() function.

[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

The first solution would be quite tedious to code and make the script slower. I'm going to try the second solution. Is there a way to somehow watch for the windows message that says the window is losing focus and IMMEDIATELY react to that? This would be something that adlib functions can't do, since they are run only periodically.

Define "IMMEDIATELY". Your AdLibEnable() function could run every 100 or 50 milliseconds, for example. Is that really too slow?

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Define "IMMEDIATELY". Your AdLibEnable() function could run every 100 or 50 milliseconds, for example. Is that really too slow?

:)

Well, there's logic like this: if A() then B()

If the window gets deactivated after the A() check but before the B() action, I would still like to to pause immediately and not perform B() on the wrong window. Specifically, A() checks for stuff on the client area with pixel checking code, in a DX game.

Of course, checking whether the window is activated at EVERY action will work, but my main concern with that is code elegance and simplicity.

Since my code performs pauses in between actions in takes anyway, adlib will probably work with at most one action done on the wrong window. However, I'm wondering if there's a way for the originally running code to continue where it left off when I go back to the original window.

Edited by palindrome

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