Jump to content

XampPause used with "HotKeySet"


jfcby
 Share

Recommended Posts

Hi,

Included is three XamplePause codes that you can use, modify, and change as needed. When putting thes scripts together I used AutoIT3 Forum and Help File.

Code 1: Pause your script with a "HotSetKey" using the keyboard "Pause/Break" key then after un-pauseing the script it re-starts at the same location specificed by you.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)

Local $msg, $lbCount, $Count, $Exit

Global $Paused
HotKeySet("{PAUSE}", "PaRsSameLocation")
HotKeySet("{ESC}", "_Exit")

GUICreate("XampPause Restart SaLoc", 275, 100); will create a dialog box that when displayed is centered
    
    GUICtrlCreateLabel('Keboard Keys: "Esc" = Exit Script' & @LF & @LF & ' and "Pause/Break" = Pause Script', 30, 5, 175, 50, $SS_CENTER)
    $lbCount = GUICtrlCreateLabel("1", 10, 75, 25, 25)
    $Count = GUICtrlCreateButton("Count", 45, 75, 50, 20)   
    $Exit = GUICtrlCreateButton("Exit", 100, 75, 50, 20)
    
GUISetState();Displays an empty dialog box
    
;Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $Count
                MsgBox(0, "You clicked on", "Yes")
                For $i = 1 to 50                    
                    Sleep(500)
                    GUICtrlSetData($lbCount, $i)
                Next
                For $i = 50 to 1 Step -1                    
                    Sleep(500)
                    GUICtrlSetData($lbCount, $i)
                Next
                MsgBox(0,"", "Count Complete...")           
            Case $msg = $Exit
                MsgBox(0, "You clicked", "Exit")
                _Exit()             
            Case $msg = $GUI_EVENT_CLOSE
                MsgBox(0, "You clicked", "Close")
                _Exit()             
        EndSelect           
    Until $msg = $GUI_EVENT_CLOSE Or $msg = $Exit

Func PaRsSameLocation()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',395,325)
    WEnd
    ToolTip("") 
EndFunc

Func _Exit()
    Exit 0
EndFunc

Code 2: Pause your script with a "HotSetKey" using the keyboard "Pause/Break" key then after un-pauseing the script it re-starts at a different location specificed by you.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Paused, $lbCount
Main()

Func Main()
Global $msg, $Count, $Exit


HotKeySet("{PAUSE}", "PaRsDifferentLocation")
HotKeySet("{ESC}", "_Exit")

GUICreate("Xamp DiffLoc", 250, 100);Creates a centered dialog box

    GUICtrlCreateLabel('Keboard Keys: "Esc" = Exit Script' & @LF & @LF & ' and "Pause/Break" = Pause Script', 30, 5, 175, 50, $SS_CENTER)
    $lbCount = GUICtrlCreateLabel("1", 10, 75, 25, 25)
    $Count = GUICtrlCreateButton("Count", 45, 75, 50, 20)   
    $Exit = GUICtrlCreateButton("Exit", 100, 75, 50, 20)
    
GUISetState();Displays an empty dialog box
    
;Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $Count
                PaRsDifferentLocation()         
            Case $msg = $Exit
                MsgBox(0, "You clicked on", "Exit")
                _Exit()
            Case $msg = $GUI_EVENT_CLOSE
                MsgBox(0, "You clicked on", "Close")
                _Exit()
        EndSelect           
    Until $msg = $GUI_EVENT_CLOSE Or $msg = $Exit
EndFunc

Func PaRsDifferentLocation()
    $Paused = NOT $Paused
        While 1
            Switch $Paused
                Case 0
                    sleep(100)
                    ToolTip('Script is "Paused"',395,325)
                Case 1
                    ToolTip("")
                    MsgBox(0, "You clicked on", "Yes")
                        For $i = 1 to 50
;MsgBox(0, "Count down!", $i)
                            Sleep(500)
                            GUICtrlSetData($lbCount, $i)
                        Next
                        For $i = 50 to 1 Step -1
;MsgBox(0, "Count down!", $i)
                            Sleep(500)
                            GUICtrlSetData($lbCount, $i)
                        Next
                        MsgBox(0,"", "count Complete...")
                EndSwitch
        WEnd
EndFunc

Func _Exit()
    Exit 0
EndFunc

Code 3: Pause your script with a "HotSetKey" then after un-pauseing a button will need to be clicked to restart script.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Opt('MustDeclareVars', 1)
Global $Paused, $lbCount
Global $msg, $lbCount, $Count, $Exit

HotKeySet("{PAUSE}", "PaRsButtonclick")
HotKeySet("{ESC}", "_Exit")

GUICreate("XampPause Button Click", 250, 100);creates a centered dialog box
    
    GUICtrlCreateLabel('Keboard Keys: "Esc" = Exit Script' & @LF & @LF & ' and "Pause/Break" = Pause Script', 30, 5, 175, 50, $SS_CENTER)
    $lbCount = GUICtrlCreateLabel("1", 10, 75, 25, 25)
    $Count = GUICtrlCreateButton("Count", 45, 75, 50, 20)   
    $Exit = GUICtrlCreateButton("Exit", 100, 75, 50, 20)
    
GUISetState();displays an empty dialog box

Main()

Func Main()
;Run the GUI until the dialog is closed
    Do
        $msg = GUIGetMsg()
        Select
            Case $msg = $Count
                MsgBox(0, "You clicked ", "Count")
                For $i = 1 to 50;Count up                   
                    Sleep(500)
                    GUICtrlSetData($lbCount, $i)
                Next
                For $i = 50 to 1 Step -1;Count down                 
                    Sleep(500)
                    GUICtrlSetData($lbCount, $i)
                Next
                MsgBox(0,"", "Count Complete...")           
            Case $msg = $Exit
                MsgBox(0, "You clicked ", "Exit")
                _Exit()
            Case $msg = $GUI_EVENT_CLOSE
                MsgBox(0, "You clicked ", "Close")
                _Exit()
        EndSelect           
    Until $msg = $GUI_EVENT_CLOSE Or $msg = $Exit
EndFunc

Func PaRsButtonclick()
    $Paused = NOT $Paused
    While $Paused
    sleep(100)
    ToolTip('Script is "Paused"',395,325)
    WEnd
    
    ToolTip("")
    GUICtrlSetData($lbCount, "1")
    Main()
EndFunc

Func _Exit()
    Exit 0
EndFunc

Learning to write scripts,

jfcby

Edited by jfcby

Determined -- Devoted -- Delivered Make your mind up -- to seriously apply yourself -- accomplishing the desired results. **** A soft answer turneth away wrath: but grievous words stir up anger. Proverbs 15:1 KJB ****

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