gspot Posted June 2, 2014 Share Posted June 2, 2014 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 expandcollapse popup#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 More sharing options...
Moderators Solution Melba23 Posted June 2, 2014 Moderators Solution Share Posted June 2, 2014 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 ;==>TogglePauseFor more details see the Interrupting a running function tutorial in the Wiki. M23 gspot 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
gspot Posted June 2, 2014 Author Share Posted June 2, 2014 I understand now. Thanks Melba23 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now