Equivalent of sleep for mouse clicks?

Windows specific questions.
Post Reply
Bimbling Bob
Posts: 5
Joined: Nov 20, 2017 19:44

Equivalent of sleep for mouse clicks?

Post by Bimbling Bob »

I know that in order to not hog the CPU while waiting for a key press from the user we have the sleep command available instead of a loop with inkey,
so instead of

Code: Select all

do
 loop until len(inkey)
 


We can simply code

Code: Select all

sleep
but is there an equivalent of the sleep command that waits for a mouse click rather than a key press, to replace a loop like this:-

Code: Select all

 
 do
  yy = GetMouse (x, y, , zz)
 loop until yy=0 and zz=1
with something that lets Windows get on with other processes until the user left-clicks on the console?
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Equivalent of sleep for mouse clicks?

Post by dodicat »

I think only getmouse catches mouse clicks.
except
inkey = chr(255) + "k" will get a left click on the window close button.

I suggest simplifying getmouse:

Code: Select all

dim as long b


dim as long b
dim as single z
 
screen 19

do
    screenlock
    cls
    z+=.01
    
    if z>3 then z=0
   
     locate(3,3)
  
   
print "Hello, left click to end  " + string(z,".")

screenunlock
sleep 1,1
loop until (getmouse(0,0,0,b)+b=1) 

 
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: Equivalent of sleep for mouse clicks?

Post by MrSwiss »

dodicat wrote:I think only getmouse catches mouse clicks.
AFAIK, in Windows, we would rather have to talk about: "event(s)" or "message(s)", which include both
(mouse- as well as keyboard-action's).
Translated to: "virtual key-press(es)", split into "key-up" and "key-down", each of which can be "captured".

The basic idea, in code, below:

Code: Select all

Do
    ' do anything, that needs to be done
    
    If Len(InKey) Then Exit Do    ' quit loop (end program!)
    Sleep(16, 1)    ' approx: 60 fps, give CPU a break
Loop
As can be seen, more than one statement is needed, to really "control" the loop.
It is functionally equivalent to:

Code: Select all

Do
    ' do anything, that needs to be done
    
    Sleep(16, 1)    ' approx: 60 fps, give CPU a break
Loop Until Len(InKey)
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Equivalent of sleep for mouse clicks?

Post by dodicat »

I had forgotten about fbgfx screenevents.
Using these:

Code: Select all

 

#include "fbgfx.bi"



Dim e As FB.event

dim as single z
 
screen 19

do
   
    screenlock
    cls
    z+=.01
    
    if z>3 then z=0
   
     locate(3,3)
  
   
print "Hello, left click to end  " + string(z,".")

screenunlock
sleep 1,1
loop until screenevent(@e) and e.button = FB.BUTTON_LEFT

 
Post Reply