Jump to content

How Do I Pause/unpause A Script?


Recommended Posts

you know how autoit has the icon in the tray, pressing it pause the script/ pressing it again unpause.. i want to know how to do this with a gui, button, and a custom tray button but it freezes the entire script.. i'll post the script in a few, unless somebody already knows whow to do it.

Link to comment
Share on other sites

  • Moderators

you know how autoit has the icon in the tray, pressing it pause the script/ pressing it again unpause.. i want to know how to do this with a gui, button, and a custom tray button but it freezes the entire script.. i'll post the script in a few, unless somebody already knows whow to do it.

You want a button menu to drop down when you hover the button? And I don't know what you mean by tray "button".

If it's the button menu, you can take a look at this: http://www.autoitscript.com/forum/index.ph...ndpost&p=165551

Edited by SmOke_N

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

i just want to pause/unpause a function, but dont want to pause the gui, i seen how this is done with hotkeys bot how can it be done with gui??

#include <GUIConstants.au3>
Global $pause = 0, $pause

GUICreate("BD",200,200,-1,-1)
$pauseme= GUICtrlCreateButton("Pause me",10,50,180,30)
$test= GUICtrlCreateButton("Open notepad",10,80,180,30)
$exit= GUICtrlCreateButton("exit",10,110,180,30)
GUISetState()

Opt("TrayMenuMode",1) 
$prefsitem  = TrayCreateItem("Pause/Unpause")
TrayItemSetOnEvent($prefsitem,"_pauseme")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exititem   = TrayCreateItem("Exit")
TrayItemSetOnEvent($prefsitem,"_ext")
TraySetState()

while 1
_loooooooop()
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE
   ExitLoop
  Case $msg = $pauseme
      _pauseme()
  Case $msg = $test
      run("notepad.exe")
  Case $msg =  $exit
      Exit
EndSelect
WEnd

func _loooooooop()
run("notepad.exe")
sleep(2000)
EndFunc

func _ext()
    Exit
EndFunc

func _pauseme()
while 1
If $pause = 0 Then 
$pause = 1
GUICtrlSetData($pauseme,"Unpause me")
$Pause = NOT $Pause
While $Pause
        sleep(10)
WEnd
If $pause = 0 Then $pause = 1
EndIf
ExitLoop
If $pause = 1 Then 
$pause = 0
GUICtrlSetData($pause,"Pause me")
$Pause = $Pause
While NOT $Pause
     ExitLoop
WEnd
If $pause = 1 Then $pause = 0
ExitLoop
EndIf
wend
EndFunc

wend
EndFunc
Edited by slightly_abnormal
Link to comment
Share on other sites

  • Moderators

Would be nice to hear if anything ever worked for you lol, but this is probably how I would have approached (don't know really, didn't give it much thought):

#include <GUIConstants.au3>
Global $pause = 0, $pause
GUICreate("BD",200,200,-1,-1)
$pauseme= GUICtrlCreateButton("Pause me",10,50,180,30)
$test= GUICtrlCreateButton("Open notepad",10,80,180,30)
$exit= GUICtrlCreateButton("exit",10,110,180,30)
GUISetState()
Opt("TrayMenuMode",1)
$prefsitem  = TrayCreateItem("Pause/Unpause")
TrayItemSetOnEvent($prefsitem,"_pauseme")
TrayCreateItem("")
$aboutitem  = TrayCreateItem("About")
TrayCreateItem("")
$exititem   = TrayCreateItem("Exit")
TrayItemSetOnEvent($prefsitem,"_ext")
TraySetState()
While 1
;_loooooooop()
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $pauseme
            _pauseme()
        Case $msg = $test
            Run("notepad.exe")
        Case $msg =  $exit
            Exit
    EndSelect
WEnd
Func _loooooooop()
    Run("notepad.exe")
    Sleep(2000)
EndFunc  ;==>_loooooooop
Func _ext()
    Exit
EndFunc  ;==>_ext
Func _pauseme()
    $pause = Not $pause
    If $pause Then 
        GUICtrlSetData($pauseme,"Unpause me")
    Else
        GUICtrlSetData($pauseme,"Pause me")
    EndIf
    While $pause
        $msg2 = GUIGetMsg()
        Select
            Case $msg2 = $GUI_EVENT_CLOSE
                ExitLoop
            Case $msg2 = $pauseme
                _pauseme()
            Case $msg2 = $test
                Run("notepad.exe")
            Case $msg2 =  $exit
                Exit
        EndSelect
    WEnd
EndFunc  ;==>_pauseme

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

i think this is what you wanted... the pause actually pauses... even the tray pause works too!

#include <GUIConstants.au3>
Global $pause = 0 

GUICreate("BD", 200, 200, -1, -1)
$pauseme = GUICtrlCreateButton("Pause me", 10, 50, 180, 30)
$test = GUICtrlCreateButton("Open notepad", 10, 80, 180, 30)
$exit = GUICtrlCreateButton("exit", 10, 110, 180, 30)
GUISetState()

Opt("TrayMenuMode", 1)
Opt("TrayOnEventMode", 1)
$prefsitem = TrayCreateItem("Pause/Unpause")
TrayItemSetOnEvent( -1, "_pauseme")
TrayCreateItem("")
$aboutitem = TrayCreateItem("About")
TrayItemSetOnEvent( -1, "_about")
TrayCreateItem("")
$exititem = TrayCreateItem("Exit")
TrayItemSetOnEvent( -1, "_ext")
TraySetState()



While 1
    
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
        Case $msg = $pauseme
            _pauseme()
        Case $msg = $test
            _loooooooop()
        Case $msg = $exit
            Exit
    EndSelect
    While $pause = 1
        $msg2 = GUIGetMsg()
        If $msg2 = $pauseme Then _pauseme()
    WEnd
WEnd

Func _loooooooop()
    Run("notepad.exe")
EndFunc ;==>_loooooooop

Func _ext()
    Exit
EndFunc ;==>_ext

Func _pauseme()
    If GUICtrlRead($pauseme) = "Pause me" Then
        GUICtrlSetData($pauseme, "Unpause me")
        $pause = 1
    Else
        GUICtrlSetData($pauseme, "Pause me")
        $pause = 0
    EndIf
EndFunc

Func _about()
    MsgBox(64,"thanks...","... Valuater",1)
EndFunc

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

By adding something like:

While $pause = 1
        $msg2 = GUIGetMsg()
        If $msg2 = $pauseme Then _pauseme()
    WEnd

In the loop?

#)

Link to comment
Share on other sites

MsgBox(64,"thanks...","... Valuater",1)

:( hey val, do you know how to get it to pause/unpause if the i stuck a while loop in the _loooooooop() func.. maybe if i change to oneventmode? lets see. :) dang the pause function keeps getting smaller, and it works!.. :think:

Welcome

glad it worked

8)

NEWHeader1.png

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