Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yet another mouse function
#2
Same mouse program but with Triple-Click:

Code: (Select All)
Rem Mouse.bas is the sample mouse trap function for QB64 PD 2023.
DefLng A-Z
Dim Shared MouseX As Integer, MouseY As Integer
Dim Shared MouseButton1 As Integer, MouseButton2 As Integer, MouseButton3 As Integer
Dim Shared MouseWheel As Integer, WheelReverse As Integer
Const ClickCount = 10 ' double click loop counter
Const ClickDelay = .1 ' double click loop delay
Color 15
Print "Mouse detect. Press <esc> to exit."
If WheelReverse Then
  Print "  Mouse wheel reverse on."
End If
Do
  x$ = InKey$
  If x$ = Chr$(27) Then Exit Do
  x = MouseDriver
  If MouseButton1 = 3 Then
      Print "Triple-Button1": MouseButton1 = 0
  Else
      If MouseButton1 = 2 Then
        Print "Double-Button1": MouseButton1 = 0
      Else
        If MouseButton1 = 1 Then
            Print "Button1": MouseButton1 = 0
        End If
      End If
  End If
  If MouseButton2 Then MouseButton2 = 0: Print "Button2"
  If MouseButton3 Then MouseButton3 = 0: Print "Button3"
  If MouseX Or MouseY Then Print "Coor:"; MouseX; MouseY
  If MouseWheel Then
      If MouseWheel = -1 Then
        Print "Mousewheel Up"
      End If
      If MouseWheel = 1 Then
        Print "Mousewheel Down"
      End If
  End If
Loop
End

Function MouseDriver
  Static X1 As Integer, Y1 As Integer ' store old values
  MouseX = 0: MouseY = 0
  If _MouseInput Then
      X = CInt(_MouseX): Y = CInt(_MouseY) ' X,Y return single
      If X <> X1 Or Y <> Y1 Then
        X1 = X: Y1 = Y
        MouseX = Y: MouseY = X ' X,Y are reversed
        While _MouseInput: Wend ' empty buffer
        MousePressed = -1
      End If
      ' single click
      MouseButton1 = _MouseButton(1)
      If MouseButton1 Then
        MouseButton1 = 1
        'MouseX = Y1
        'MouseY = X1
        MousePressed = -1
        MouseCount = 0
        ' double click
        Do
            _Delay ClickDelay
            MouseCount = MouseCount + 1
            If MouseCount >= ClickCount Then Exit Do
            If _MouseInput Then
              If _MouseButton(1) Then
                  MouseButton1 = 2
                  MouseCount = 0
                  ' triple click
                  Do
                    _Delay ClickDelay
                    MouseCount = MouseCount + 1
                    If MouseCount >= ClickCount Then Exit Do
                    If _MouseInput Then
                        If _MouseButton(1) Then
                          MouseButton1 = 3
                          Exit Function
                        End If
                    End If
                  Loop
              End If
            End If
        Loop
      End If
      MouseButton2 = _MouseButton(2)
      If MouseButton2 Then
        'MouseX = Y1
        'MouseY = X1
        MousePressed = -1
      End If
      MouseButton3 = _MouseButton(3)
      If MouseButton3 Then
        MousePressed = -1
      End If
      MouseWheel = _MouseWheel
      If MouseWheel Then
        ' reverse mousewheel value
        If WheelReverse Then
            If MouseWheel = -1 Then
              MouseWheel = 1
            Else
              If MouseWheel = 1 Then
                  MouseWheel = -1
              End If
            End If
        End If
      End If
  End If
  MouseDriver = -1
End Function

And, yes, you could probably add a Quad-Click or double-right click. But an nth click would result in an endless timer loop.


Attached Files
.bas   mouse.bas (Size: 7.18 KB / Downloads: 51)
Reply


Messages In This Thread
Yet another mouse function - by eoredson - 10-09-2023, 03:34 AM
RE: Yet another mouse function - by eoredson - 10-09-2023, 04:32 AM
RE: Yet another mouse function - by eoredson - 10-09-2023, 06:50 AM
RE: Yet another mouse function - by grymmjack - 10-09-2023, 06:54 PM
RE: Yet another mouse function - by eoredson - 10-09-2023, 11:40 PM
RE: Yet another mouse function - by grymmjack - 10-10-2023, 12:15 AM
RE: Yet another mouse function - by SMcNeill - 10-10-2023, 01:07 AM
RE: Yet another mouse function - by eoredson - 10-10-2023, 01:49 AM
RE: Yet another mouse function - by eoredson - 10-10-2023, 03:27 AM



Users browsing this thread: 5 Guest(s)