[bb] Mouse Click Functions by Matty [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:42

Previous topic - Next topic

BlitzBot

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) Select
;
;
;
;Mouse Usage Algorithm
;
;
;Call MouseInput(M,N) with M being the minimum time in millisecs in which to count a click as separate
;from holding the mouse down, and N being the maximum time in millisecs for a click to count as a
;doubleclick
;
;
;The return value is the sum of the parameters in the const statement
;below, leftbutton, Right button etc.  
;
;
;Some sample values for the two parameters for the MouseInput() function would be 60 and 450.
;
;
;



Const LeftButton=1,Rightbutton=2,MiddleButton=4,DoubleClick=8,HeldDown=16,SingleClick=32

Type MouseObj

Field ButtonClicked
Field TimeClicked

End Type

Function MouseInput(MinClickTime,DoubleClickSpeed)
;Click Mode = 1 is a Click, = 2 is a Held Down button
;

Time=MilliSecs()
For Button.MouseObj=Each MouseObj
If Time>ButtonTimeClicked+DoubleClickSpeed Then Delete button
Next



If MouseDown(LeftButton) And MouseDown(RightButton)=0 Then MyMouseInput=CheckButton(LeftButton,Time,MinClickTime,DoubleClickSpeed)
If MouseDown(Rightbutton) And MouseDown(LeftButton)=0 Then MyMouseInput=CheckButton(RightButton,Time,MinClickTime,DoubleClickSpeed)
If MouseDown(MiddleButton) Then MyMouseInput=CheckButton(MiddleButton,Time,MinClickTime,DoubleClickSpeed)
If MouseDown(LeftButton) And MouseDown(RightButton) Then MyMouseInput=CheckButton(LeftButton+RightButton,Time,MinClickTime,DoubleClickSpeed)

Return MyMouseInput


End Function

Function CheckButton(WhichButton,Time,MinClickTime,DoubleClickSpeed)
ClickMode=SingleClick
For Button.MouseObj=Each MouseObj
If Time>ButtonTimeClicked+MinClickTime And Time<ButtonTimeClicked+DoubleClickSpeed Then
;Ie we have a click, not a mouse button held down...
ClickMode=DoubleClick
Else
ClickMode=HeldDown
ButtonTimeClicked=Time
EndIf
Next
Select ClickMode

Case SingleClick

Button.MouseObj=New MouseObj
ButtonButtonClicked=WhichButton
ButtonTimeclicked=Time
Return SingleClick+Whichbutton


Case DoubleClick

For Button.Mouseobj=Each MouseObj
Delete Button
Next
Return DoubleClick+Whichbutton


Case HeldDown

Return HeldDown+WhichButton


End Select



End Function


Comments : none...