Jump to content

Window appears to be in focus but isn't


 Share

Recommended Posts

I am running this script but often the window isn't detected, even though it is on top. If I click the window no change is apparent but that seems to trigger the script to continue on. It seems as though the window isn't active even though it is the top most window and it looks to be in focus.... Is there a fool proof way to get this window active? Thanks for any help in advance.

Run("C:\Program Files\Kurzweil Educational Systems\Kurzweil 3000\Kurzweil 3000.exe")

WinWaitActive("Kurzweil 3000 Trial Version","&Activate Now")

If WinExists("Kurzweil 3000 Trial Version","&Activate Now") Then
        WinActivate("Kurzweil 3000 Trial Version","&Activate Now")
    ControlClick("Kurzweil 3000 Trial Version", "&Activate Now","") 
Else
    MsgBox(4096, "Fail", "Failed to see window")
EndIf
Edited by Alias
Link to comment
Share on other sites

Just an observation, but you might want to put a WinWaitActive after the WinActivate, sometimes it takes a bit of time to work through the system and actually activate the window.

If that doesn't do it, you might try this:

Func ForceActive ($windowName, $windowText = "", $timeOut)
    Local $timer = TimerInit()
    While TimerDiff($timer) < $timeOutand Not WinActive ($windowName, $windowText) ;5 Seconds is more than generous
        WinActivate ($windowName, $windowText);
    WEnd
    If TimerDiff($timer) > $timeOut Then Return 0 ;Passed the timeout
    Return 1
EndFunc

I've coded this pretty much from memory, but it should work. ACT! has been a bit ... lazy at times about activating itself, so I've had to bash it over the head with this to get it to wake up.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Just an observation, but you might want to put a WinWaitActive after the WinActivate, sometimes it takes a bit of time to work through the system and actually activate the window.

If that doesn't do it, you might try this:

Func ForceActive ($windowName, $windowText = "", $timeOut)
    Local $timer = TimerInit()
    While TimerDiff($timer) < $timeOutand Not WinActive ($windowName, $windowText) ;5 Seconds is more than generous
        WinActivate ($windowName, $windowText);
    WEnd
    If TimerDiff($timer) > $timeOut Then Return 0 ;Passed the timeout
    Return 1
EndFunc

I've coded this pretty much from memory, but it should work. ACT! has been a bit ... lazy at times about activating itself, so I've had to bash it over the head with this to get it to wake up.

I tried WinActivate before and it didn't make any difference for some reason. I am getting an error off your function.

==> Badly formatted "Func" statement.:

Link to comment
Share on other sites

Func ForceActive ($windowName, $windowText = "", $timeOut=5000);5 Seconds is more than generous
    Local $timer = TimerInit()
    While TimerDiff($timer) < $timeOutand Not WinActive ($windowName, $windowText) 
        WinActivate ($windowName, $windowText);
    WEnd
    If TimerDiff($timer) > $timeOut Then Return 0 ;Passed the timeout
    Return 1
EndFunc

Forgot that the optionals have to be last, perils of coding from memory Posted Image

Edited by Fulano

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Func ForceActive ($windowName, $windowText = "", $timeOut=5000);5 Seconds is more than generous
    Local $timer = TimerInit()
    While TimerDiff($timer) < $timeOutand Not WinActive ($windowName, $windowText) 
        WinActivate ($windowName, $windowText);
    WEnd
    If TimerDiff($timer) > $timeOut Then Return 0 ;Passed the timeout
    Return 1
EndFunc

Forgot that the optionals have to be last, perils of coding from memory Posted Image

Thanks, but it still isn't working, it is a dialog style window with a button that needs to be pressed....I am thinking there must be a child_window type of option but I can't find anything....argh!

Link to comment
Share on other sites

Hi Alias,

Not sure about the inactive window problem however, since you are using ControlClick() function the window does not need to be active for this function to succeed.

Unless you use any Send() commands or mouseclick() later on you shouldn't need to worry about the window be active at all just that the window exists which I see you have already coded.

Good Luck

-1

What are we going to do tonight Brain?Same thing we do every night Pinky try to automate the world.

Link to comment
Share on other sites

Hmm, You could replace the WinActive () test with

(StringInString (WinGetText("[active]", $windowText) and StringInString (WinGetTitle("[active]", $windowTitle))
This will blindly grab the text from the active window, but it might not grab it either if WinActive isn't detecting it.

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

Link to comment
Share on other sites

Not sure about the inactive window problem however, since you are using ControlClick() function the window does not need to be active for this function to succeed.

Good point, and much simpler! :(

#fgpkerw4kcmnq2mns1ax7ilndopen (Q, $0); while ($l = <Q>){if ($l =~ m/^#.*/){$l =~ tr/a-z1-9#/Huh, Junketeer's Alternate Pro Ace /; print $l;}}close (Q);[code] tag ninja!

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