Timppa Posted December 13, 2015 Share Posted December 13, 2015 Hello guys!I have this pause function that most of us use:Func Pause() $Paused = NOT $Paused While $Paused _FreeText_ShockWave("Program is paused.") Sleep(100) WEnd EndFuncThis literally pauses everything.The problem is that the reason for pause is that I change options or I have to do something else for moment, if I change options, the checkboxes and radio buttons works fine and so on, but the problem is that for some options I have $GUI_DISABLE and $GUI_ENABLE depending on what do I enable/disable. For example, I want the program to be faster (skip Sleep's and use more CPU), the GUI disables the checkboxes inside another radio button. Since I am very bad at explaining I show you an example: This is when the Default is checked, disables the input of Random (1 to 3) And now this is the Random option that disables the Default's input. BUT, when my script is paused, it will not disable anything because it loops Sleep. So is there a chance to set options while the program is paused? To use another kind of pause script than Sleep loop (for example a script that kind of stops doing everything but still remembers where it was the last time it was used).The script for enabling/disabling GUI is here:If GUICtrlRead($rDefault) = 1 Then If BitAND(GUICtrlGetState($iDefault),$GUI_DISABLE) Then GUICtrlSetState($iDefault,$GUI_ENABLE) If BitAND(GUICtrlGetState($iRandom1),$GUI_ENABLE) Then GUICtrlSetState($iRandom1,$GUI_DISABLE) If BitAND(GUICtrlGetState($iRandom2),$GUI_ENABLE) Then GUICtrlSetState($iRandom2,$GUI_DISABLE) Else If BitAND(GUICtrlGetState($iDefault),$GUI_ENABLE) Then GUICtrlSetState($iDefault,$GUI_DISABLE) If BitAND(GUICtrlGetState($iRandom1),$GUI_DISABLE) Then GUICtrlSetState($iRandom1,$GUI_ENABLE) If BitAND(GUICtrlGetState($iRandom2),$GUI_DISABLE) Then GUICtrlSetState($iRandom2,$GUI_ENABLE) EndIfThanks in advance! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted December 13, 2015 Moderators Share Posted December 13, 2015 Timppa,Create a little wrapper Pause function like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cRadio_On = GUICtrlCreateRadio("On", 10, 10, 200, 20) GUICtrlSetState($cRadio_On, $GUI_CHECKED) $cRadio_Off = GUICtrlCreateRadio("Off", 10, 40, 200, 20) $cLabel = GUICtrlCreateLabel("On", 10, 100, 200, 40) GUICtrlSetFont($cLabel, 18) $cPause = GUICtrlCreateButton("Pause", 10, 200, 80, 30) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cPause ConsoleWrite("Paused" & @CRLF) _Advanced_Pause(5000) ConsoleWrite("Unpaused" & @CRLF) Case $cRadio_On GUICtrlSetData($cLabel, "On") Case $cRadio_Off GUICtrlSetData($cLabel, "Off") EndSwitch WEnd Func _Advanced_Pause($iDelay) $nBegin = TimerInit() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $cRadio_On GUICtrlSetData($cLabel, "On") Case $cRadio_Off GUICtrlSetData($cLabel, "Off") EndSwitch Until TimerDiff($nBegin) > $iDelay EndFuncAs you can see, the radios work all the time.M23 Timppa 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...
Timppa Posted December 13, 2015 Author Share Posted December 13, 2015 Thanks melba! That looks good and works fine However I have not tested it on my program yet, but if it works on your example, it should work on me aswell. Will try later today when I get back. Link to comment Share on other sites More sharing options...
Timppa Posted December 20, 2015 Author Share Posted December 20, 2015 (edited) Umm, I found one problem when using this. The GUI works as it should and X button closes the program while paused which is good.But, I cannot resume the program. It should pause from F1 and resume from F1 too ($Paused = !$Paused) (or Not $Paused, whatever).It kind of pauses it forever? Yes I modified it to thisFunc Pause() If $Paused Then $nBegin = 1000 * 60 * 1000000 $Paused = NOT $Paused $nBegin = TimerInit() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit ;Case $cRadio_On ; GUICtrlSetData($cLabel, "On") ;Case $cRadio_Off ;GUICtrlSetData($cLabel, "Off") EndSwitch Until TimerDiff($nBegin) > 1000 * 60 * 1000000 EndFuncI kind of don't want 5 seconds pause because it depends how long I want it to be paused. That's why I added 1000 * 60 * 1000000 but it will not "wear off" if I press F1.Any other solution for this one? EDIT: Since people often do not help others if they don't try to improve the script by themselves, this was only solution I could of think (to use with TimerInit) Case "{F1}" $Paused = Not $Paused $nBegin = 1000 * 60 * 1000000I added that after every cases but it did not work... As I assumed Edited December 20, 2015 by Timppa Link to comment Share on other sites More sharing options...
mikell Posted December 20, 2015 Share Posted December 20, 2015 Before doing more and more mistakes you must have a look at HotKeySet examples in the helpfile Link to comment Share on other sites More sharing options...
Timppa Posted December 20, 2015 Author Share Posted December 20, 2015 Yes, I do have this to toggle pause:HotKeySet("{F1}", "Pause")What do I have to do now? Link to comment Share on other sites More sharing options...
mikell Posted December 20, 2015 Share Posted December 20, 2015 Now you have to understand how the TogglePause() func works, so you can go exactly the same way in your script Link to comment Share on other sites More sharing options...
mikell Posted December 20, 2015 Share Posted December 20, 2015 (edited) <> Edited December 20, 2015 by mikell Link to comment Share on other sites More sharing options...
Timppa Posted December 20, 2015 Author Share Posted December 20, 2015 (edited) But.. Yes, it works whenever I once press F1, it pauses it correctly but WILL NOT unpause it anymore if the same hotkey is pressed.I copy pasted the HotKeySet("{F1}", "Pause") inside the Func Pause() and still it did not unpause it, is there way to do something like Case HotKey("{F1}") ?I checked from google "autoit case hotkey" and found this only But I guess that has nothing to do with it. Can you even tell me am I supposed to use the HotKey like "Case HotKey F1" or what?Seriously can't figure out. EDIT: Wait, there is "Case "{ESC}" in that example, but I did the same way and did not affect at all o_oEDIT2: Case "{F1}" AdLibRegister("Pause") did not work neither did Case "{F1}" Pause() ... ._.EDIT3: Added this $nBegin = TimerInit() Do Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit ;Case $cRadio_On ;GUICtrlSetData($cLabel, "On") ;Case $cRadio_Off ;GUICtrlSetData($cLabel, "Off") EndSwitch Switch @HotKeyPressed Case "{F1}" Pause() EndSwitch Until TimerDiff($nBegin) > 1000 * 60 * 1000000Did not work, I still try AdLibRegister and the original method I did with the script.EDIT4: Nope, both of them did not work..... Edited December 20, 2015 by Timppa Link to comment Share on other sites More sharing options...
mikell Posted December 20, 2015 Share Posted December 20, 2015 (edited) OKHere is a working example . When you hit F1 you pause/unpause (using the global $Paused variable), and when paused it will automatically unpause if the delay is reached (using TimerDiff)HotKeySet("{F1}", "Pause") HotKeySet("{ESC}", "Terminate") Global $Paused = 0 Global $delay = 3000 While 1 ToolTip('Script is NOT paused', 0, 0) Sleep(100) WEnd Func Pause() $Paused = Not $Paused $nBegin = TimerInit() While $Paused ; exit loop if $Paused = 0 ToolTip('Script is paused', 0, 0) ; exit loop if $delay reached If TimerDiff($nBegin) > $delay Then $Paused = 0 Wend EndFunc Func Terminate() Exit EndFunc ;==>Terminate Edited December 20, 2015 by mikell comments added Timppa 1 Link to comment Share on other sites More sharing options...
Timppa Posted December 20, 2015 Author Share Posted December 20, 2015 Allright thanks! Finally it worked. I also added that Switch in the While loop because the buttons did not work before that.Did not think it could be used like that 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