Jump to content

Ensure target window is active


palindrome
 Share

Recommended Posts

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.

Link to comment
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

Link to comment
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.
Link to comment
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
Link to comment
Share on other sites

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
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...