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


Messages In This Thread
Smart Pause - by SMcNeill - 03-28-2024, 02:45 AM
RE: Smart Pause - by Pete - 03-29-2024, 01:33 AM



Users browsing this thread: 1 Guest(s)