Jump to content

Pause key and GUI


Go to solution Solved by Melba23,

Recommended Posts

Good morning

Im using this code to pause script with HotKeySet("{PAUSE}", "TogglePause")

Func TogglePause()
        $fPaused = Not $fPaused
        While $fPaused
            Sleep(100)
            ToolTip('Script is "Paused"', 0, 0)
        WEnd
        ToolTip("")
    EndFunc   ;==>TogglePause

The problem is when i use it in a GUI with button to pause (Pausar), first time i click pause button (Pausar) it works but then if i click again doesnt continue code (like it happens if i press the real Pause key of keyboard).

What am i doing wrong? How can i do this?

i Send the all script at bottom.

Thanks in advance

#include <MsgBoxConstants.au3>
AutoItSetOption("TrayIconDebug", 1);0-off

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

Global $fPaused = False
Global $status1 = "active" & @CRLF

; AdlibRegister("_close", 3000) ;equivalent to settimer

HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("+{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ; Shift-Alt-d
HotKeySet("{F9}", "_localtest")



#Region ### START Koda GUI section ### Form=d:\documents and settings\ptpro.pvmarques\desktop\autoit\gso portin\form1.kxf
$Form1_1 = GUICreate("GSO Portin", 182, 272, 700, 391)
GUISetBkColor(0xA6CAF0)
$Label1 = GUICtrlCreateLabel("GSO Portin", 24, 224, 146, 36)
GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0xE9E7E2)
$Button_iniciar = GUICtrlCreateButton("Iniciar", 40, 24, 105, 33, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0x50CB62)
GUICtrlSetTip(-1, "[F4] Inicia robot se este estiver parado")
GUICtrlSetCursor(-1, 0)
$Button_Pausar = GUICtrlCreateButton("Pausar", 40, 70, 105, 33, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xFFFF80)
GUICtrlSetTip(-1, "Pausa robot")
GUICtrlSetCursor(-1, 0)
$Button_reload = GUICtrlCreateButton("Reload", 40, 172, 105, 33, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0x0080FF)
GUICtrlSetCursor(-1, 0)
$Button_stop = GUICtrlCreateButton("STOP", 40, 118, 105, 33, BitOR($WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif")
GUICtrlSetBkColor(-1, 0xEB6A14)
GUICtrlSetCursor(-1, 0)
Dim $Form1_1_AccelTable[1][2] = [["{F4}", $Button_iniciar]]
GUISetAccelerators($Form1_1_AccelTable)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button_iniciar
            MsgBox(0, "", "O robot vai iniciar")
        Case $Button_Pausar
            send("{PAUSE}")
            ; TogglePause()
        Case $Button_stop
            Terminate()
        Case $Button_reload
            MsgBox(0, "", "Temos que arranjar um reload")

    EndSwitch
WEnd



    Func TogglePause()
        $fPaused = Not $fPaused
        While $fPaused
            Sleep(100)
            ToolTip('Script is "Paused"', 0, 0)
            
        WEnd
        ToolTip("")
    EndFunc   ;==>TogglePause

    Func Terminate()
        Exit
    EndFunc   ;==>Terminate

    Func ShowMessage()
        MsgBox($MB_SYSTEMMODAL, "", "This is a message.")
    EndFunc   ;==>ShowMessage


    Func _localtest()
        Local $status1 = "Inactive" & @CRLF
        ConsoleWrite($status1)
        MsgBox(0, 0, "test")
    EndFunc   ;==>_localtest
Link to comment
Share on other sites

  • Moderators
  • Solution

gspot,

While the script is paused you remain within the TogglePause function - this means that the script will no longer look for GUI events such as the Pausar button being pressed. But you can make the button active by looking for it being fired inside the function like this:

Func TogglePause()
    $fPaused = Not $fPaused
    While $fPaused
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $Button_Pausar
                $fPaused = Not $fPaused
        EndSwitch
        ToolTip('Script is "Paused"', 0, 0)
    WEnd
    ToolTip("")
EndFunc   ;==>TogglePause
For more details see the Interrupting a running function tutorial in the Wiki. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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