Sign in to follow this  
Followers 0
mini

HELP How to make a Stop/Sleep Button

3 posts in this topic

Hello I've see some programs like my, but the codes they are using are not what I have.

Can anyone help me on my coding please.

this is what I have:

#Region
Global $Form1 = GuiCreate("Test stoping loop", 380, 270)
Global $start=GuiCtrlCreateButton("Start",1,4,93,32)
Global $Stop=GuiCtrlCreateButton("Stop",184,4,83,32)
GuiSetState()
#EndRegion

While 1
$msg=GuiGetMsg()
If $msg=-3 Then Exit
If $msg=$start Then Start() ;Start
If $msg=$stop then Stop() ;Stop
Wend

Func Stop();Stop
    sleep( 120000 )
EndFunc

Func Start();Start
     Run("notepad.exe")
if not WinActive( "Untitled - " ) Then
    WinActivate( "Untitled - " )
EndIf
while 1
    if not ProcessExists("notepad.exe") Then
        Run("notepad.exe")
            if not WinActive( "Untitled - " ) Then
            WinActivate( "Untitled - " )
            sleep(2000)
            send("test123")
            send("{tab}")
            send("test456")
            send("{ENTER}")
        EndIf
    EndIf
WEnd
EndFunc

the loop works perfectly, if i exit the notepad, he opens a new one and writes. the stoping button is my main prob now.

thx for all replays

Share this post


Link to post
Share on other sites



#include <GUIConstantsEx.au3>
Opt("GUIOnEventMode", 1)

Local $Form1, $start, $stop, $fRun

#Region
$Form1 = GUICreate("Test stoping loop", 380, 270)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
$start = GUICtrlCreateButton("Start", 1, 4, 93, 32)
GUICtrlSetOnEvent($start, "_Start")
$stop = GUICtrlCreateButton("Stop", 184, 4, 83, 32)
GUICtrlSetOnEvent($stop, "_Stop")
GUISetState()
#EndRegion

$fRun = False

While 1
    If $fRun Then
        While $fRun
            If Not ProcessExists("notepad.exe") Then
                Run("notepad.exe")
                
                If Not WinActive("Untitled - ") Then
                    WinActivate("Untitled - ")
                    Sleep(2000)
                    Send("test123")
                    Send("{tab}")
                    Send("test456")
                    Send("{ENTER}")
                EndIf
            EndIf
            ToolTip("Still running", 0, 0)
            Sleep(1000)
        WEnd
        ToolTip("")
    EndIf
    Sleep(20) ; Idle around
WEnd

Func _Stop()
    $fRun = False
EndFunc   ;==>_Stop

Func _Start();Start
    $fRun = True
EndFunc   ;==>Start

Func _Quit()
    GUIDelete()
    Exit
EndFunc

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Hi, i just trying to help. You can use HotKeySet to call the functions. Here is the example.

Example:

#Region
Global $Form1 = GUICreate("Test stoping loop", 380, 270)
Global $start = GUICtrlCreateButton("Start", 1, 4, 93, 32)
Global $Stop = GUICtrlCreateButton("Stop", 184, 4, 83, 32)
GUISetState()
HotKeySet("{Insert}", "Start")
HotKeySet("{DEL}", "Stop") ; You can use hotkeyset to call the stop function
#EndRegion

While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then Exit
    If $msg = $start Then Start() ;Start
    If $msg = $Stop Then Stop() ;Stop
WEnd

Func Stop();Stop
    MsgBox(0, "", "Stop function called!"&@CRLF&"Sleeping for 120 seconds... zzzz.. :P") ; Show that Stop function is successfully called
    Sleep(120000)
EndFunc   ;==>Stop

Func Start();Start
    Run("notepad.exe")
    If Not WinActive("Untitled - Notepad") Then
        WinActivate("Untitled - Notepad")
    EndIf
    While 1 ; <-Stop btn is not functioning because of this loop replace loop before this
        If Not ProcessExists("notepad.exe") Then
            Run("notepad.exe")
        Else
            If Not WinActive("Untitled - Notepad") Then
                WinActivate("Untitled - Notepad")
            Else
                Sleep(2000)
                Send("test123")
                Send("{tab}")
                Send("test456")
                Send("{ENTER}")
            EndIf
        EndIf
    WEnd
EndFunc   ;==>Start
Edited by ichigo325

[size="2"][font="Lucida Sans Unicode"][b][/b][/font][/size]

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