Jump to content

Pause and continue script?


 Share

Recommended Posts

Well im trying to do so if i press a button (pause) then the script will pause then if i press "start" it will start again,but it's not working.

Can someone help me?

If anything else would be wrong you could tell me also :), but i guess everything is right exept the pause/start code :)

Thanks

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\omnibook\Skrivbord\CZ.kxf\CZ.kxf
$Form2 = GUICreate("Z Clicker 1.1", 346, 282, 293, 161)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\ZC.bmp", 0, 0, 345, 281, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSetState($Pic1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("(Not allowed)", 112, 16, 110, 40, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\Start.bmp", 0)
$Button2 = GUICtrlCreateButton("(Not allowed)", 232, 16, 110, 40, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\pause.bmp", 0)
$Button3 = GUICtrlCreateButton("(Not allowed)", 256, 216, 78, 47, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\exit2.bmp", 0)
$Button4 = GUICtrlCreateButton("(Not allowed)", 120, 104, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\5sec.bmp", 0)
$Button5 = GUICtrlCreateButton("(Not allowed)", 120, 144, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\10sec.bmp", 0)
$Button6 = GUICtrlCreateButton("(Not allowed)", 120, 184, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\15 sec.bmp", 0)
$Group1 = GUICtrlCreateGroup("Click Delay", 120, 80, 73, 25, BitOR($BS_CENTER,$BS_FLAT,$WS_BORDER,$WS_CLIPSIBLINGS), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlCreateGroup("Click Delay", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $Button1
        While 1 
MouseClick("left");;;;5 SEC DELAY CLICK
sleep(5000)
MouseClick("left")
sleep(5000)
MouseClick("left")
WEnd
    
Case $Button2;;;;;;;;;;PAUSAR
    ("{PAUSE}")
    
Case $Button3;;;;;;OM EXIT DÅ EXIT
    Exit

Case $Button4
        
    While 1 
MouseClick("left");;;;5 SEC DELAY CLICK
sleep(5000)
MouseClick("left")
sleep(5000)
MouseClick("left")
WEnd

Case $Button5
    While 1 
MouseClick("left");;;;10 SEC DELAY CLICK
sleep(10000)
MouseClick("left")
sleep(10000)
MouseClick("left")
WEnd

Case $Button6
    
    While 1 
MouseClick("left");;;;15 SEC DELAY CLICK
sleep(15000)
MouseClick("left")
sleep(15000)
MouseClick("left")
WEnd
     
    
    
    Case $GUI_EVENT_CLOSE
    Exit

EndSwitch
WEnd
Link to comment
Share on other sites

Well im trying to do so if i press a button (pause) then the script will pause then if i press "start" it will start again,but it's not working.

Can someone help me?

If anything else would be wrong you could tell me also :) , but i guess everything is right exept the pause/start code :)

Thanks

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=C:\Documents and Settings\omnibook\Skrivbord\CZ.kxf\CZ.kxf
$Form2 = GUICreate("Z Clicker 1.1", 346, 282, 293, 161)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\ZC.bmp", 0, 0, 345, 281, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSetState($Pic1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("(Not allowed)", 112, 16, 110, 40, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\Start.bmp", 0)
$Button2 = GUICtrlCreateButton("(Not allowed)", 232, 16, 110, 40, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\pause.bmp", 0)
$Button3 = GUICtrlCreateButton("(Not allowed)", 256, 216, 78, 47, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\exit2.bmp", 0)
$Button4 = GUICtrlCreateButton("(Not allowed)", 120, 104, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\5sec.bmp", 0)
$Button5 = GUICtrlCreateButton("(Not allowed)", 120, 144, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\10sec.bmp", 0)
$Button6 = GUICtrlCreateButton("(Not allowed)", 120, 184, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\15 sec.bmp", 0)
$Group1 = GUICtrlCreateGroup("Click Delay", 120, 80, 73, 25, BitOR($BS_CENTER,$BS_FLAT,$WS_BORDER,$WS_CLIPSIBLINGS), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlCreateGroup("Click Delay", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    Case $Button1
        While 1    
MouseClick("left");;;;5 SEC DELAY CLICK
sleep(5000)
MouseClick("left")
sleep(5000)
MouseClick("left")
WEnd
    
Case $Button2;;;;;;;;;;PAUSAR
    ("{PAUSE}")
    
Case $Button3;;;;;;OM EXIT DÅ EXIT
    Exit

Case $Button4
        
    While 1    
MouseClick("left");;;;5 SEC DELAY CLICK
sleep(5000)
MouseClick("left")
sleep(5000)
MouseClick("left")
WEnd

Case $Button5
    While 1    
MouseClick("left");;;;10 SEC DELAY CLICK
sleep(10000)
MouseClick("left")
sleep(10000)
MouseClick("left")
WEnd

Case $Button6
    
    While 1    
MouseClick("left");;;;15 SEC DELAY CLICK
sleep(15000)
MouseClick("left")
sleep(15000)
MouseClick("left")
WEnd
     
    
    
    Case $GUI_EVENT_CLOSE
    Exit

EndSwitch
WEnd

OIC... the pause code you used... Pause... is a toggle

and it neatly pauses execution of your application....

heh...

I'd replace that with a loop that has as it's exit condition, selecting the restart button...

Edited by everseeker

Everseeker

Link to comment
Share on other sites

Example from the helpfile:

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc
Link to comment
Share on other sites

Example from the helpfile:

; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage");Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc

Or... what he said :)

Everseeker

Link to comment
Share on other sites

Case $Button2;       PAUSAR
        
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Pauser"',0,0)
    WEnd
    ToolTip("")

This is the function you need... use this in place of the function you currently have assigned to pausing.....

Edited by everseeker

Everseeker

Link to comment
Share on other sites

Case $Button2;       PAUSAR
        
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Pauser"',0,0)
    WEnd
    ToolTip("")

This is the function you need... use this in place of the function you currently have assigned to pausing.....

wait... that will not work... hang on while I work on this...

Everseeker

Link to comment
Share on other sites

wait... that will not work... hang on while I work on this...

Case $Button2;       PAUSAR
        
    While 1=1
        sleep(100)
        ToolTip('Script is "Pauser"',0,0)
        $nMsg = GUIGetMsg()
        If $nMsg=$Button1 then 
            exitloop
        endif
    WEnd
    ToolTip("")

Give that a shot...

(I am assuming that $Button1 will only evaluate as "True" when the button is pressed... correct?)

Edited by everseeker

Everseeker

Link to comment
Share on other sites

  • Developers

Case $Button2;       PAUSAR
        
    While 1=1
        sleep(100)
        ToolTip('Script is "Pauser"',0,0)
        If $Button1 then 
            exitloop
        endif
    WEnd
    ToolTip("")

Give that a shot...

(I am assuming that $Button1 will only evaluate as "True" when the button is pressed... correct?)

C'mon folks... this is never ever going to work properly. rule 1: Thow shall not use a Sleep() in a GUI message loop. Best shot would be to use the GUI in event mode.

Secondly: Where are you updating $button1 in your proposal ?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

C'mon folks... this is never ever going to work properly. rule 1: Thow shall not use a Sleep() in a GUI message loop. Best shot would be to use the GUI in event mode.

Secondly: Where are you updating $button1 in your proposal ?

1. Came from example....

2. My bad... I was editing the OP while you were replying...

I was not evaluating the correct expression....

Everseeker

Link to comment
Share on other sites

Case $Button2;       PAUSAR
        
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Pauser"',0,0)
    WEnd
    ToolTip("")

This is the function you need... use this in place of the function you currently have assigned to pausing.....

Doesn't work,well it pauses the script but i can turn it on or click on anything on my menu,not even shut it down with.
Link to comment
Share on other sites

1. Came from example....

2. My bad... I was editing the OP while you were replying...

I was not evaluating the correct expression....

$nMsg = GUIGetMsg()

If $nMsg=$Button1 then

exitloop

needs to be inserted into each of your delay loops is you EVER want to be able to get out of them...

Soon as you get to that While 1.... you're done

Everseeker

Link to comment
Share on other sites

$nMsg = GUIGetMsg()

If $nMsg=$Button1 then

exitloop

needs to be inserted into each of your delay loops is you EVER want to be able to get out of them...

Soon as you get to that While 1.... you're done

Your script seems to have several issues.... What exactly are you attempting to do?

Everseeker

Link to comment
Share on other sites

Here's the simpliest way of pausing a script with a button (on event mode):

#include <GUIConstants.au3>
Global $bool=False
Opt("GUIOnEventMode",1)
GUICreate("Test GUI",200,100)
GUICtrlCreateButton("Pause!",10,10)
GUICtrlSetOnEvent(-1,"pause")
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()


while 1
    while $bool
        Sleep(100)
    WEnd
    
    Sleep(50)
WEnd


Func close ()
    Exit
EndFunc

Func pause ()
    If NOT $bool Then
        $bool=True
        ToolTip("Script is paused!")
    Else
        $bool=False
        ToolTip("")
    EndIf
EndFunc
Edited by monoceres

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

  • Developers

Looks like a clear case of running before knowing how to crawl .. :)

Try to take more than 5 seconds to study the posted example and to interpret it. After that you can come back for questions.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I think i got it now,but now it comes up with an error "'EndIf' statenent with no matching "If" statement",but there is a If on the right place :S

Code..

#include <GUIConstants.au3>
Global $bool=False
Opt("GUIOnEventMode",1)
#Region ### START Koda GUI section ### Form=C:\Documents and Settings\omnibook\Skrivbord\CZ.kxf\CZ.kxf
$Form2 = GUICreate("Z Clicker 1.1", 346, 282, 293, 161)
$Pic1 = GUICtrlCreatePic("C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\ZC.bmp", 0, 0, 345, 281, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS))
GUICtrlSetState($Pic1, $GUI_DISABLE)
$Button1 = GUICtrlCreateButton("(Not allowed)", 112, 16, 110, 40, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\Start.bmp", 0)
$Button2 = GUICtrlCreateButton("(Not allowed)", 232, 16, 110, 40, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\pause.bmp", 0)
$Button3 = GUICtrlCreateButton("(Not allowed)", 256, 216, 78, 47, $BS_BITMAP)
GUICtrlSetOnEvent(-1,"pause")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
GUISetOnEvent($GUI_EVENT_CLOSE,"close")
GUISetState()


while 1
    while $bool
        Sleep(100)
    WEnd
   
    Sleep(50)
WEnd


Func close ()
    Exit
EndFunc

Func pause ()
    If NOT $bool Then
        $bool=True
        ToolTip("Script is paused!")
    Else
        $bool=False
        ToolTip("")
        EndIf
EndFunc
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\exit2.bmp", 0)
$Button4 = GUICtrlCreateButton("(Not allowed)", 120, 104, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\5sec.bmp", 0)
$Button5 = GUICtrlCreateButton("(Not allowed)", 120, 144, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\10sec.bmp", 0)
$Button6 = GUICtrlCreateButton("(Not allowed)", 120, 184, 75, 27, $BS_BITMAP)
GUICtrlSetImage(-1, "C:\Documents and Settings\omnibook\Skrivbord\Z Clicker 1.1\Data\15 sec.bmp", 0)
$Group1 = GUICtrlCreateGroup("Click Delay", 120, 80, 73, 25, BitOR($BS_CENTER,$BS_FLAT,$WS_BORDER,$WS_CLIPSIBLINGS), $WS_EX_CLIENTEDGE)
GUICtrlSetFont(-1, 9, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x00FF00)
GUICtrlCreateGroup("Click Delay", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
    
    Case $Button1
        While 1 
MouseClick("left");;;;5 SEC DELAY CLICK
sleep(5000)
WEnd
    
    

Case $Button2;     PAUSAR
       
    While 1
        endif
    WEnd
    
    
Case $Button3;;;;;;OM EXIT DÅ EXIT
    
Exit    

Case $Button4
    
    While 1 
        
MouseClick("left");;;;5 SEC DELAY CLICK
sleep(5000)
WEnd


Case $Button5
    While 1 
MouseClick("left");;;;10 SEC DELAY CLICK
sleep(10000)
WEnd

Case $Button6
    
    While 1 
MouseClick("left");;;;15 SEC DELAY CLICK
sleep(15000)
WEnd
     
    
    
    Case $GUI_EVENT_CLOSE
    Exit

EndSwitch
WEnd

EndFunc
Edited by Zisly
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...