How to check if the mousebutton was pressed or released.

Share your advanced PureBasic knowledge/code with the community.
User avatar
Joakim Christiansen
Addict
Addict
Posts: 2452
Joined: Wed Dec 22, 2004 4:12 pm
Location: Norway
Contact:

How to check if the mousebutton was pressed or released.

Post by Joakim Christiansen »

Code: Select all

;0=false, 1=pressed, 2=down, 3=released
If MouseButton(1)
  If MB_Left = 0
    MB_Left = 1
  Else
    MB_Left = 2
  EndIf
Else
  If MB_Left = 3
    MB_Left = 0
  ElseIf MB_Left = 2
    MB_Left = 3
  EndIf
EndIf
This should be placed in the main loop after ExamineMouse().
I like logic, hence I dislike humans but love computers.
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Nice!
This is the way i used to do it:

Code: Select all

If MouseButton(1);<-if current key status is PUSHED
      If pka.b=0:pka.b=1:EndIf;<-if previous key status was NOT PUSHED
ElseIf pka.b;<-else (if previous key status was PUSHED and current key status is NOT PUSHED):
      pka.b=0;<-set previous key status to NOT PUSHED.
EndIf
Yours is more complete, because it detects the releasing edge too. Mine only detects the pressing edge.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply