Jump to content

Advanced Pause


Timppa
 Share

Recommended Posts

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

EndFunc

This 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:

def3.thumb.png.73f3515ee42c3e5dd726c627d This is when the Default is checked, disables the input of Random (1 to 3)

ran3.thumb.png.c1d7a670bf965f835085c1818 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)
   EndIf

Thanks in advance!

Link to comment
Share on other sites

  • Moderators

Timppa,

Create a little wrapper Pause function like this:

#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

EndFunc

As you can see, the radios work all the time.

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

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 this

Func 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

EndFunc

I 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 * 1000000

I added that after every cases but it did not work... As I assumed :(

Edited by Timppa
Link to comment
Share on other sites

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_o

EDIT2: 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 * 1000000

Did not work, I still try AdLibRegister and the original method I did with the script.

EDIT4: Nope, both of them did not work..... :D

Edited by Timppa
Link to comment
Share on other sites

OK
Here 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 by mikell
comments added
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...