Sign in to follow this  
Followers 0
michaelslamet

Get current window information and activate it

7 posts in this topic

I'm a new AutoIt user (it's yesterday exactly). After years without programming, now I think it's a good time to learn a new programming language just to make some of my works easier.

I would like to create a script that know current window, send a keystroke on other window and then back to previous window. This is the code I create:

#Include <WinAPI.au3>

$bLoop = 1

While $bLoop = 1

$handle = WinGetHandle("WinGetTitle()", "") ;get the title of the active window

WinWaitActive("Message from webpage") ;wait this window appear

Send("{ENTER}") ;automatically click OK

WinActivate("$handle") ;switch back to previous window

WEnd

I need the script to run all the time waiting for the "Message from webpage" window appear, automatically click "OK" on that window, switch back to previous window before the "Message from webpage" window appear, waiting for the window appear again.

It didn't work :( It wait the window to appear, automatically click "OK" but doesn't back to previous window :)

Please advice.

Many thanks!

Michael.

Share this post


Link to post
Share on other sites



$hWnd = WinGetHandle("[ACTIVE]", "")

will give you the handle of the currently active window.

However reading your request you might want to take a look in the help file for the ControlClick() command.

The program "Au3Info.exe" located in the install folder gives you all relevant info needed to fill the ControlClick() syntax.

And if you're planing to do it in a loop I recommend adding a sleep() or the script will choke the CPU.

Share this post


Link to post
Share on other sites

KaFu,

Many thanks for your clue. But after few hours, I still cant make it work :(

; #Include <WinAPI.au3>

$bLoop = 1

While $bLoop = 1

$hWnd = WinGetHandle("[ACTIVE]", "")

WinWaitActive("Message from webpage")

Send("{ENTER}")

ControlFocus($hwnd)

WEnd

Try this and that, but still doesn't work :)

Somebody please help :)((((((((((((((((

Thanks!!

Michael.

Share this post


Link to post
Share on other sites

Are you sure you're looking for a real window?

"WinWaitActive("Message from webpage")" Sounds more like waiting for a pop-up browser window. Check if you can capture infos on that window via au3info.exe... if it's a browser window, maybe better switch to _ie udf functions?

Share this post


Link to post
Share on other sites

What does the AutoIt tool say?

Post the output of the summary page in a code tag so we can see what is going on.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

@KaFu dan bo8ster: thanks for your reply!

"Message from popup" is a browser popup, but that is what we consider as a window too, isn't it? Previous code just doesn't save current window info, so it cant switch back when it move to another window. But... finally I get it work perfectly:) The function below is not coded by me, I get it when googling. Basicly what this script do is everytime the window "message from webpage" appear, it will automatically click the default button and then switch back to active window before the window "message from webpage" appear.

Hope this will help other member who had problem with activate window.

$jendela = WinGetActive()

$bLoop = 1

While $bLoop = 1

$jendela = WinGetActive()

if WinExist("Message from webpage") then

WinActivate("Message from webpage")

Send("{ENTER}")

WinActivate($jendela[0])

endif

WEnd

Func WinGetActive()

Dim $window[2]

Dim $winlist

$winlist = WinList()

For $i = 1 to $winlist[0][0]

If $winlist[$i][0] <> "" AND IsVisible($winlist[$i][1]) Then

$window[0] = $winlist[$i][0]

$window[1] = $winlist[$i][1]

ExitLoop

EndIf

Next

Return $window

EndFunc

Func IsVisible($handle)

If BitAnd( WinGetState($handle), 2 ) Then

Return 1

Else

Return 0

EndIf

EndFunc

Share this post


Link to post
Share on other sites

Code tags help. Put in Global for the bars

Global $jendela = WinGetActive()
Global $bLoop = 1
While $bLoop = 1
    $jendela = WinGetActive()
    If WinExist("Message from webpage") Then
        WinActivate("Message from webpage")
        Send("{ENTER}")
        WinActivate($jendela[0])
    EndIf
WEnd

Func WinGetActive()
    Dim $window[2]
    Dim $winlist
    $winlist = WinList()
    For $i = 1 To $winlist[0][0]
        If $winlist[$i][0] <> "" And IsVisible($winlist[$i][1]) Then
            $window[0] = $winlist[$i][0]
            $window[1] = $winlist[$i][1]
            ExitLoop
        EndIf
    Next
    Return $window
EndFunc   ;==>WinGetActive


Func IsVisible($handle)
    If BitAND(WinGetState($handle), 2) Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc   ;==>IsVisible

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

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