Jump to content

Loop and keep a window focused until event.


Recommended Posts

Hey guys,

I have a script that launches a program called Ventrilo, it then clicks connect then waits for a popup window, well if I click to launch the app but then click away from the window the process doesn't complete because focus has been removed.

I would like to know ( I don't want to block input as I know how to do that ) how to put a loop in there to keep WinActivate until the process is complete.

While "Window Isn't Active"
       Make the window active until it has closed the popup then can end / exit
WEnd

Here's my current code:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   AutoIt Version: 3.1.0                                                       ;
;   Author: NeoBorn <neo underscore born at hotmail dot com>                    ;
;   Script Function: Ventrilo Launch and Close Information Box Tool.            ;
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   PseudoCode:                                                                 ;
;   1. To Open the Ventrilo program                                             ;
;   2. To Wait for a popup window                                               ;
;   3. When popup window is there close it                                      ;
;   4. Exit the program                                                         ;
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;

#NoTrayIcon
Opt("WinTitleMatchMode", 2)
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

Global $Vent = "Ventrilo", $Ventx = "Ventrilo.exe", $MsgDay = "Message of the Day"
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Function Calls~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
RunProgy()
ByeBye()
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func RunProgy()
    Run("E:\Program Files\Ventrilo\Ventrilo.exe", "E:\Program Files\Ventrilo\", _
            @SW_SHOWDEFAULT)
    WinActive($Vent)
    WinActivate($Vent)
    GogoGadget()
EndFunc   ;==>RunProgy

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func GogoGadget()
    If ProcessExists($Ventx) Then
        WinActivate($Vent)
        WinActive($Vent)
        Send("!o")
        WinWaitActive($MsgDay)
        WinActivate($MsgDay)
        Send("{SPACE}")
        Exit
    Else
        If Not ProcessExists($Ventx) Or Not WinExists($Vent) Or Not WinExists($MsgDay) Then
            MsgBox(64, "Error...", "The process " & $Ventx & ", or the windows " & $Vent & " & " & $MsgDay & " do not exist!")
            Exit
        EndIf
    EndIf
EndFunc   ;==>GogoGadget
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func ByeBye()
    Exit
EndFunc   ;==>ByeBye

I also have some questions about Global / Local / Dim.

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

Hi,

have a look at Do until or While ... Wend.

The only thing you need to know is the break condition. e.g. the window title changes or something else.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

End result

Added a while statement and controlclick. This means teh window always gets the focus etc. <3 Teh.meger

couldn't do it ( well without much frustration or giving up ) without you! :)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   AutoIt Version: 3.1.0                                                       
;   Author: NeoBorn <neo underscore born at hotmail dot com>                    
;   Script Function: Ventrilo Launch and Close Information Box Tool.            
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;   PseudoCode:                                                                 
;   1. To Open the Ventrilo program                                             
;   2. To Wait for a popup window                                               
;   3. When popup window is there close it                                      
;   4. Exit the program                                                         
;øøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøøø;

#NoTrayIcon
Opt("WinTitleMatchMode", 2)
Opt("GUIOnEventMode", 1)  ; Change to OnEvent mode

Global $Vent = "Ventrilo", $Ventx = "Ventrilo.exe", $MsgDay = "Message of the Day"
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Function Calls~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
RunProgy()
ByeBye()
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Functions~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func RunProgy()
    Run("E:\Program Files\Ventrilo\Ventrilo.exe", "E:\Program Files\Ventrilo\", _
            @SW_SHOWDEFAULT)
    WinActive($Vent)
    WinActivate($Vent)
    GogoGadget()
EndFunc   ;==>RunProgy

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
; Changes were made to this function to loop and also use the controlclick command.

Func GogoGadget()
    While ProcessExists($Ventx)
        WinActivate($Vent)
        If WinActive($Vent) = 1 Then
            ControlClick($Vent, "C&onnect", 1009)
        EndIf
        If WinExists($MsgDay) = 1 Then
            WinClose($MsgDay)
            Exit
        EndIf
    WEnd
EndFunc   ;==>GogoGadget
;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;
Func ByeBye()
    Exit
EndFunc   ;==>ByeBye
Edited by Neoborn

~Projects~1. iPod Ejector 1.0 - Tool Used To Eject iPod in Windows - Uses DevEject.exe :P2. SmartFTP Close Popup Tool - Closes reminders from freeware SmartFTP.~Helpful Links For New Users~1. LXP's Learning AutoIT PDF Guide - <<< Go here for a PDF Guide on learning AutoIT from the ground up!<<<2. AutoIt 1-2-3 <<<Want to learn more about AutoIT quickly? Go Here<<<3. How To Install The Beta And Production Versions Of AutoIT / SciteAutoIT

Link to comment
Share on other sites

quote]End result

Added a while statement and controlclick. This means teh window always gets the focus etc. <3 Teh.meger

couldn't do it ( well without much frustration or giving up ) without you! biggrin.gif[

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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