Sandhya

activate a window

8 posts in this topic

I have tried the below code for activating a window if it appears.

if WinExists ("Connect devices") Then

WinActivate ("Connect devices")

Send ("{ENTER}")

EndIf

But failed. Sometimes it works.

The window is not getting activated.

Can you pls help me on this?

 

Share this post


Link to post
Share on other sites



it works. Thanks.

But at sometimes, the window is not getting activated.

At all times the window will not appear. So at times, it appears, i have to send "ENTER"

Share this post


Link to post
Share on other sites

This is what I use for my own auto launcher to test out certain aspects of games I make you may find some things in it helpful. It hasn't failed yet it will even launch my personal game when i have something full screen up.

 

Global $windowTitle = "insert name here" ; defines the window title for the script
Global $shortcutTitle = "insert name here" ; defines the shortcut title for the script

Global $checkWin = WinExists($windowTitle) ; sees if the window is open or not

RunWindow() ; runs the RunWindow function

Func RunWindow() ; runs the window
    If $checkWin = 0 Then ;0 = not launched
        ShellExecute($shortcutTitle, "", @DesktopDir) ; launches the window from your desktop
        $checkWin = 1 ; enables next block of code to activate
    EndIf
    If $checkWin = 1 Then ;1 = launched
        WinActivate($windowTitle) ; supposed to activate the window
        WinWaitActive($windowTitle) ; waits for the window to be active before continuing
        Sleep(10000) ; waits 10 seconds to make sure window is loaded fully
    EndIf
EndFunc

Hope this helps you :)

Share this post


Link to post
Share on other sites

i have taken some points from your code like below.

Local $checkagain = WinExists("ERROR")
If $checkagain = 1 Then
   WinActivate("ERROR")
   Send ("{ENTER}")
EndIf

But of no use. Whether my code is correct?

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Ill do it like this:

If WinExists("ERROR") Then
   WinWaitActive("ERROR")
   Send ("{ENTER}")
EndIf

or

If WinWait("ERROR") Then
    WinActivate("ERROR")
    Send("{ENTER}")
EndIf

 

Edited by 232showtime

ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Ill do it like this:

If WinExists("ERROR") Then
   WinWaitActive("ERROR")
   Send ("{ENTER}")
EndIf

or

If WinWait("ERROR") Then
    WinActivate("ERROR")
    Send("{ENTER}")
EndIf

 

I'd add in this above the Send line just to double check that the window is indeed active.
 

ControlClick("ERROR", "", "Control ID of somewhere on the ERROR message like where the error message itself is", "left", 1)

Then use this instead of Send to ensure that you don't have to manually click the button.

ControlSend("ERROR", "", "Control ID of the button you wish to use", "{ENTER}")

Finished code would look like this

If WinExists("ERROR") Then
    WinWaitActive("ERROR")
    ControlClick("ERROR", "", "Control ID of the error message", "left", 1)
    ControlSend("ERROR", "", "Control ID of the button", "{ENTER}")
EndIf

or

If WinWait("ERROR") Then
    WinActivate("ERROR")
    ControlClick("ERROR", "", "Control ID of the error message", "left", 1)
    ControlSend("ERROR", "", "Control ID of the button", "{ENTER}")
EndIf

 

Edited by xxaviarxx

Share this post


Link to post
Share on other sites

thanks.

both works.

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