Alias Posted March 24, 2010 Share Posted March 24, 2010 (edited) 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 March 24, 2010 by Alias Link to comment Share on other sites More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 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 More sharing options...
Alias Posted March 24, 2010 Author Share Posted March 24, 2010 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 More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 (edited) 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 EndFuncForgot that the optionals have to be last, perils of coding from memory Edited March 24, 2010 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 More sharing options...
Alias Posted March 24, 2010 Author Share Posted March 24, 2010 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 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 More sharing options...
Negative1 Posted March 24, 2010 Share Posted March 24, 2010 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 More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 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 More sharing options...
Fulano Posted March 24, 2010 Share Posted March 24, 2010 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now