BASIC

Author Topic: detecting mouse events  (Read 2274 times)

loganite

  • Guest
detecting mouse events
« on: 2008-Jan-16 »
Mousestate is good but sometimes you only want to fire an event once. The code below shows an easy way to do it. I think there are alternative ways but this one has worked well for me.


WHILE TRUE
   MOUSESTATE mx,my,b1,b2


   IF b1=1 AND lb1=0 THEN mouseb1down()
   
   IF b1=1 AND lb1=1 THEN mouseb1pressed()
   
   IF b1=0 AND lb1=1 THEN mouseb1up()
   
   lb1=b1   //record the state of the button

   PRINT "mouse b1 down count : "+countb1down,0,0
   PRINT "mouse b1 pressed count : " +countb1pressed,0,10
   PRINT "mouse b1 up count : "+countb1up,0,20

   SHOWSCREEN
WEND

FUNCTION mouseb1down:
   INC countb1down,1
ENDFUNCTION

FUNCTION mouseb1pressed:
   INC countb1pressed,1
ENDFUNCTION

FUNCTION mouseb1up:
   INC countb1up,1
ENDFUNCTION