Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Smart Pause
#1
Code: (Select All)
Print "A 10 second pause, with no break method"
Pause 10, -1 'this has to run for 10 seconds, and no input/process from the user will change that

Print "A 10 second pause, with ONLY mouse break early"
Pause 10, 1 + 4

Print "A pause, with no time limit, and ONLY mouse break"
Pause 0, 1 + 4

Print "A pause, no time limit, with only active window keyboard input break"
Pause 0, 1 + 2

Print "A 10 second pause, which any keypress or mouse click can break"
Pause 10, 0

Sub Pause (time As _Float, exclude_code As Long)
'exclude_code is the binary value of things we don't want to allow to break Pause
'1 = Window lost focus
'2= No Mouse breaking pause
'4 - No Keyboard breaking pause
'8 - No Keyup events break pause
'16 - No modifier keys breaking pause (Shift/Ctrl/Alt)
t# = Timer + time
Do
_Limit 10 'we're a pause. We don't need to do a bunch of crap per second.
If (exclude_code And 1) Then 'don't unpause until window has focus or time has ran out
If _WindowHasFocus = 0 Then _Continue
End If
If (exclude_code And 2) = 0 Then 'mouse clicks break pause
While _MouseInput: Wend
If _MouseButton(1) Or _MouseButton(2) Then Exit Do
End If
If (exclude_code And 4) = 0 Then 'we allow keyboard input (of some sort) to break pause
k = _KeyHit
If (exclude_code And 8) Then If k < 0 Then k = 0 'but we don't allow keyup events to do it
If (exclude_code And 16) Then 'here we don't allow modifier keys to do it
Select Case k
Case 100304, 100303, -100304, -100303 'shift up/down
_Continue
Case 100306, 100305, -100306, -100305 'ctrl up/down
_Continue
Case 100308, 100307, -100308, -100307 'alt up/down
_Continue
End Select
End If
End If
If time <> 0 And Timer > t# Then Exit Do
If k <> 0 Then Exit Do
Loop
End Sub

And here we have a customizable "Pause" routine, which allows for a few things which SLEEP doesn't.

Set it to allow mouse clicks to break pause.
Set it to allow pause to only break when the window has focus.
Remove modifier keys from the list of acceptable keys to break pause (no shift/ctrl/alt breaking pause).
Set it so that only keydown events break pause and not keyup events.
Timed events, or events without no time limit.


One thing of note: This also allows you to create your very own endless loop! Set it with no time limit for a pause, with no input allowed to break the pause, and you have permanently paused your program until you click the red "X" in the top right corner and closed it.

I really wouldn't recommend doing that, but hey, if that's your thing....
Reply
#2
Add a correctly written _EXIT subroutine and you'd have to use Task manager to close it. Big Grin 

I always coded my own pause routines for my apps. Sleep is nice for pausing when debugging. You can use it with INKEY$ and still get input...

Code: (Select All)
Sleep
b$ = InKey$
Print b$
End

...but that's a pretty Mickey Mouse way to avoid a loop.

You know in 2005 you could do something like this in QuickBasic...

Code: (Select All)
Z1 = Timer: Z3 = Timer
Do
    '''IF MSE >= 0 THEN EX% = 2: CALL MDRIVER(EX%, B$, POP)
    Z2 = Timer
    If Z1 > Timer Then Z1 = Z1 - 86400: Rem MIDNIGHT ISSUES
    If Z3 > Timer Then Z3 = Z2: Rem MIDNIGHT ISSUES
    If Abs(Z2 - Z3) > .2 Then Sound 3000, 3: Z1 = Z2: Rem PROG WAS MINIMIZED
    '''IF ABS(Z1 - Z2) > TM THEN CALL SSR
    B$ = InKey$
    If B$ <> "" Then
        '''IF MSE >= 0 THEN EX% = -1: CALL MDRIVER(EX%, B$, POP)
        Exit Do
    End If
    Z3 = Z2
Loop

However QB64 doesn't have the lag problem on min, so this little nugget has turned into fool's gold... Oh unless you developers want to break QB64 to make it more 100% QuickBasic compatible!  Big Grin Big Grin Big Grin

Pause for a moment and think about it...

Fun stuff.

Pete
Reply




Users browsing this thread: 1 Guest(s)