December 04, 2020, 11:01:12 AM

Author Topic: [bb] Mouse Click Functions by Matty [ 1+ years ago ]  (Read 553 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] Mouse Click Functions by Matty [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : Mouse Click Functions
Author : Matty
Posted : 1+ years ago

Description : Simply execute the function "MouseInput(A,B)" and the return value will tell you if the user has double clicked, single clicked or is holding the mouse down with either the left, right, middle or any combination of those mouse buttons.

Code :
Code: BlitzBasic
  1. ;
  2. ;
  3. ;
  4. ;Mouse Usage Algorithm
  5. ;
  6. ;
  7. ;Call MouseInput(M,N) with M being the minimum time in millisecs in which to count a click as separate
  8. ;from holding the mouse down, and N being the maximum time in millisecs for a click to count as a
  9. ;doubleclick
  10. ;
  11. ;
  12. ;The return value is the sum of the parameters in the const statement
  13. ;below, leftbutton, Right button etc.  
  14. ;
  15. ;
  16. ;Some sample values for the two parameters for the MouseInput() function would be 60 and 450.
  17. ;
  18. ;
  19. ;
  20.  
  21.  
  22.  
  23. Const LeftButton=1,Rightbutton=2,MiddleButton=4,DoubleClick=8,HeldDown=16,SingleClick=32
  24.  
  25. Type MouseObj
  26.  
  27. Field ButtonClicked
  28. Field TimeClicked
  29.  
  30. End Type
  31.  
  32. Function MouseInput(MinClickTime,DoubleClickSpeed)
  33. ;Click Mode = 1 is a Click, = 2 is a Held Down button
  34. ;
  35.  
  36. Time=MilliSecs()
  37. For Button.MouseObj=Each MouseObj
  38.         If Time>ButtonTimeClicked+DoubleClickSpeed Then Delete button
  39. Next
  40.  
  41.  
  42.  
  43. If MouseDown(LeftButton) And MouseDown(RightButton)=0 Then MyMouseInput=CheckButton(LeftButton,Time,MinClickTime,DoubleClickSpeed)
  44. If MouseDown(Rightbutton) And MouseDown(LeftButton)=0 Then MyMouseInput=CheckButton(RightButton,Time,MinClickTime,DoubleClickSpeed)
  45. If MouseDown(MiddleButton) Then MyMouseInput=CheckButton(MiddleButton,Time,MinClickTime,DoubleClickSpeed)
  46. If MouseDown(LeftButton) And MouseDown(RightButton) Then MyMouseInput=CheckButton(LeftButton+RightButton,Time,MinClickTime,DoubleClickSpeed)
  47.  
  48. Return MyMouseInput
  49.  
  50.  
  51. End Function
  52.  
  53. Function CheckButton(WhichButton,Time,MinClickTime,DoubleClickSpeed)
  54. ClickMode=SingleClick
  55.         For Button.MouseObj=Each MouseObj
  56.                 If Time>ButtonTimeClicked+MinClickTime And Time<ButtonTimeClicked+DoubleClickSpeed Then
  57.                         ;Ie we have a click, not a mouse button held down...
  58.                         ClickMode=DoubleClick
  59.                 Else
  60.                         ClickMode=HeldDown
  61.                         ButtonTimeClicked=Time
  62.                 EndIf
  63.         Next
  64. Select ClickMode
  65.  
  66. Case SingleClick
  67.  
  68. Button.MouseObj=New MouseObj
  69. ButtonButtonClicked=WhichButton
  70. ButtonTimeclicked=Time
  71. Return SingleClick+Whichbutton
  72.  
  73.  
  74. Case DoubleClick
  75.  
  76. For Button.Mouseobj=Each MouseObj
  77. Delete Button
  78. Next
  79. Return DoubleClick+Whichbutton
  80.  
  81.  
  82. Case HeldDown
  83.  
  84. Return HeldDown+WhichButton
  85.  
  86.  
  87. End Select
  88.  
  89.  
  90.  
  91. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal