November 28, 2020, 10:58:08 AM

Author Topic: [bb] MouseHold() by blade007 [ 1+ years ago ]  (Read 574 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] MouseHold() by blade007 [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : MouseHold()
Author : blade007
Posted : 1+ years ago

Description : Detects if a mouse button has been held down for a specific amount of time.

Use Mouseupdate() inside the main loop to update


Code :
Code: BlitzBasic
  1. Graphics 640,480,16,2
  2. SetBuffer BackBuffer()
  3.  
  4. Dim MousePress(12)
  5.  
  6. ;main loop
  7. While Not KeyDown(1)
  8.         If MouseHold(1,2000)
  9.                 Text 0,0,"The left mouse button has been held down for 2 seconds."
  10.         Else
  11.                 Text 0,0,"Hold down the left mouse button"
  12.         EndIf
  13.        
  14.         Flip
  15.         Cls
  16.         ;update the mouse buttons
  17.         MouseUpdate()
  18. Wend
  19.  
  20. Function MouseUpdate()
  21.         For buttons = 1 To 12
  22.                 If MouseDown(buttons)
  23.                         If MousePress(buttons) = False Then MousePress(buttons) = MilliSecs()
  24.                 Else
  25.                         MousePress(buttons) = 0
  26.                 EndIf
  27.         Next
  28. End Function
  29.                        
  30. Function MouseHold(ButtonSelected,HoldDelay)
  31.         If MouseDown(buttonselected) And (MilliSecs() - MousePress(buttonselected)) > HoldDelay And MousePress(buttonselected) <> 0
  32.                 Return True
  33.         EndIf
  34. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal