Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Do Loop, Sleep and Mouse Button
#4
Code: (Select All)
Do
Do
x = x + 1
Locate 1, 1: Print x
Loop Until x Mod 100 = 0 'a natural exit condition for this loop
If PauseForInput = -1 Then Exit Do

Do
y = y + 1
Locate 2, 1: Print y
Loop Until y Mod 100 = 0 'again a way for this loop to end
If PauseForInput = -1 Then Exit Do
Loop


Function PauseForInput
_KeyClear
Do
k = _KeyHit: If k > 0 Then PauseForInput = k: Exit Function
While _MouseInput: Wend: If _MouseButton(1) Then PauseForInput = -1: Exit Function
_Delay .05 'not a high priority loop here; play nice with background processes
Loop
End Function


My solution to this type little problem.  See if it makes sense to you and if it's simple enough to understand.  Wink

Instead of your SLEEP statement, I swapped in a simple little pause routine that reports if the mouse was clicked or if a key was pressed. On a key press, it simply moves on to the next loop. On a mouseclick (-1), it exits the loop. It's that easy of a process.
Reply


Messages In This Thread
Do Loop, Sleep and Mouse Button - by Dimster - 09-05-2025, 06:19 PM
RE: Do Loop, Sleep and Mouse Button - by bplus - 09-05-2025, 09:10 PM
RE: Do Loop, Sleep and Mouse Button - by Pete - 09-05-2025, 11:03 PM
RE: Do Loop, Sleep and Mouse Button - by SMcNeill - 09-05-2025, 11:21 PM
RE: Do Loop, Sleep and Mouse Button - by Pete - 09-05-2025, 11:43 PM
RE: Do Loop, Sleep and Mouse Button - by Dimster - 09-06-2025, 12:57 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Setting mouse to ignore outside of _NewImage PhilOfPerth 11 712 12-18-2025, 07:20 PM
Last Post: Pete
  Exiting sub while inside a loop PhilOfPerth 5 507 12-05-2025, 09:40 AM
Last Post: PhilOfPerth
  Using modulo to loop through lists fistfullofnails 3 708 09-03-2025, 11:50 PM
Last Post: fistfullofnails
  Stopping repeated mouse-key press PhilOfPerth 8 851 09-02-2025, 11:28 PM
Last Post: Pete
  _MessageBox ignores default button johngreening 2 598 04-27-2025, 07:34 PM
Last Post: hsiangch_ong

Forum Jump:


Users browsing this thread: 1 Guest(s)