Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best Double Click method....
#1
My current Mouse UDTs dont allow for it directly, I can of course implement it but I'm interested to see how/if you guys have methods for it...

Thanks

John
Reply
#2
Code: (Select All)
Do
    mouse clkcnt, lb
    If clkcnt = 2 Then Sound 1000, .1
Loop

Sub mouse (clkcnt, lb)
    Static z1
    While _MouseInput: Wend
    If z1 Then If Abs(Timer - z1) > .25 Then z1 = 0: clkcnt = 0
    If lb = 2 Then lb = 0 ' Click cycle completed.
    If lb = 1 And _MouseButton(1) = 0 Then lb = 2 ' Button released.
    If lb = -1 Then lb = 1 ' Button held down.
    If lb = 0 Then lb = _MouseButton(1)
    If lb = -1 Then z1 = Timer: clkcnt = clkcnt + 1: Locate 1, 1: Print "Click Count ="; clkcnt; "  ";
End Sub

Pete
Reply
#3
(10-30-2025, 03:20 AM)Pete Wrote:
Code: (Select All)
Do
    mouse clkcnt, lb
    If clkcnt = 2 Then Sound 1000, .1
Loop

Sub mouse (clkcnt, lb)
    Static z1
    While _MouseInput: Wend
    If z1 Then If Abs(Timer - z1) > .25 Then z1 = 0: clkcnt = 0
    If lb = 2 Then lb = 0 ' Click cycle completed.
    If lb = 1 And _MouseButton(1) = 0 Then lb = 2 ' Button released.
    If lb = -1 Then lb = 1 ' Button held down.
    If lb = 0 Then lb = _MouseButton(1)
    If lb = -1 Then z1 = Timer: clkcnt = clkcnt + 1: Locate 1, 1: Print "Click Count ="; clkcnt; "  ";
End Sub

Pete
Damn Pete, WEND! SOUND! Showing ones age there aint ya! Thanks though, I appreciate it even though its only for one button and doesn't have a specific time limit option for a double click as a parameter...it acceptable!

John (Sorry for being cheeky sir!)
Reply
#4
The time limit is .25 seconds. You can change that as needed. The other buttons can be coded the same as the left. The mouse wheel can be included, just be sure you place it in the While:Wend loop as...

While _MouseInput
mw = mw + _MouseWheel
Wend

Code: (Select All)
Do
mouse clkcnt, lb, rb, mb, mw
Locate 1, 1: Print "Left Click Count: "; clkcnt;: If clkcnt = 2 Then Sound 1000, .1
Locate 2, 1: Print "Left Button Status: "; lb
Locate 3, 1: Print "Middle Button Status:"; mb
Locate 4, 1: Print "Right Button Status: "; rb
Locate 5, 1: Print "Mouse Wheel Status: "; mw: If mw Then _Delay .1 ' Delay allows it to show.
Loop

Sub mouse (clkcnt, lb, rb, mb, mw)
Static z1
If mw Then mw = 0
While _MouseInput
mw = mw + _MouseWheel: If mw Then mw = mw \ Abs(mw) ' Limit to 1 or -1 for up or down.
Wend
If z1 Then If Abs(Timer - z1) > .25 Then z1 = 0: clkcnt = 0
Select Case lb
Case 2: lb = 0 ' Click cycle completed.
Case 1: If _MouseButton(1) = 0 Then lb = 2 ' Button released.
Case -1: lb = 1 ' Button held down.
Case 0: lb = _MouseButton(1)
End Select
Select Case rb
Case 2: rb = 0 ' Click cycle completed.
Case 1: If _MouseButton(2) = 0 Then rb = 2 ' Button released.
Case -1: rb = 1 ' Button held down.
Case 0: rb = _MouseButton(2)
End Select
Select Case mb
Case 2: mb = 0 ' Click cycle completed.
Case 1: If _MouseButton(3) = 0 Then mb = 2 ' Button released.
Case -1: mb = 1 ' Button held down.
Case 0: mb = _MouseButton(3)
End Select
If lb = -1 Then z1 = Timer: clkcnt = clkcnt + 1
End Sub

Pete
Reply
#5
I gave you a +1 but still, come on man! I know you taught me and it;s not my place to say but is a Mouse_State Type not something you'd consider? I'll ask nicely, though in my head, a Master Mouse type with 2 mouse state udts in it and a clicktime value....then were cooking on gas!

Love ya!

John
Reply
#6
https://qb64phoenix.com/forum/showthread.php?tid=138  <-- My MBS routine.  (Mouse Button Status)

It doesn't do double clicks natively, but it does give you clicks and once you have those, the code for double clicks is rather trivial to add.  (It does the all important click, hover, hold, drag events for us.)

Code: (Select All)

Do
   result = mbs
   if result = 1 then 'right mouse click, check results
          click = click + 1
          if click = 2 then 
               tick_timer = 0 'no need to wait any longer; we have our double click already
           else
               tick_timer = TIMER(0.001) + 0.2  'two tenths of a second to double click 
           end if
   end if
   if click then
       if TIMER > tick_timer then 'we've passed that 0.2 seconds of time for a double click
           if click = 2 then
                'it's a double click
           else then
                'it's a single click click
           end if
       end if
       click = 0: tick_timer = 0 'reset counter and timer
   end if 
LOOP


untested pseudocode written on my ipad, so it may need a little tweaking, but that's the general concept behind the process.

Get a click... start a timer.  If you get a second click in the allotted time, it's a double click.  If the time passes without that second click coming, it's a single click.

MBS works good with this simple little code as it already deals with the hold events and such for us.  I *could* add in the double-click to the routine, but it honestly seemed unnecessary and just something extra to track and process when most programs don't need it.  It's easy enough to add into a program, like above, for those cases where a double click is actually warranted.
Reply
#7
I did a routine with UDTs for a button demo with hardware acceleration. Taking the above and converting it to UDT's is similar. In this demo you can drag the suare...

Code: (Select All)
Type MyMouse
    x As Integer
    y As Integer
    lb As Integer
    rb As Integer
    mb As Integer
    mw As Integer
    clkcnt As Integer
    prevx As Integer
    prevy As Integer
    drag As Integer
End Type
Dim m As MyMouse

Locate 2, 39: Print Chr$(219);
Do
    mouse m
    Locate 1, 1: Print "Left Click Count:    "; m.clkcnt;: If m.clkcnt = 2 Then Sound 1000, .1
    Locate 2, 1: Print "Left Button Status:  "; m.lb
    Locate 3, 1: Print "Middle Button Status:"; m.mb
    Locate 4, 1: Print "Right Button Status: "; m.rb
    Locate 5, 1: Print "Mouse Wheel Status:  "; m.mw: If m.mw Then _Delay .1 ' Delay allows it to show.
    Locate 7, 1: Print "Row and Column: "; m.y; " "; m.x; "  ";
    If m.y Then
        If Screen(m.y, m.x, 0) = 219 Or m.drag Then
            If m.lb = -1 Then
                m.drag = -1
            Else
                If m.drag Then
                    If m.y <> m.prevy Or m.x <> m.prevx Then
                        Locate m.prevy, m.prevx: Print Chr$(32);
                        Locate m.y, m.x: Print Chr$(219);
                    End If
                End If
            End If
        End If
    End If
Loop

Sub mouse (m As MyMouse)
    Static z1
    m.prevx = m.x: m.prevy = m.y
    If m.mw Then m.mw = 0
    While _MouseInput
        m.mw = m.mw + _MouseWheel: If m.mw Then m.mw = m.mw \ Abs(m.mw) ' Limit to 1 or -1 for up or down.
    Wend
    m.x = _MouseX
    m.y = _MouseY
    If z1 Then If Abs(Timer - z1) > .25 Then z1 = 0: m.clkcnt = 0
    Select Case m.lb
        Case 2: m.lb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(1) = 0 Then m.lb = 2: m.drag = 0 ' Button released.
        Case -1: m.lb = 1 ' Button held down.
        Case 0: m.lb = _MouseButton(1)
    End Select
    Select Case m.mb
        Case 2: m.mb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(3) = 0 Then m.mb = 2 ' Button released.
        Case -1: m.mb = 1 ' Button held down.
        Case 0: m.mb = _MouseButton(3)
    End Select
    Select Case m.rb
        Case 2: m.rb = 0 ' Click cycle completed.
        Case 1: If _MouseButton(2) = 0 Then m.rb = 2 ' Button released.
        Case -1: m.rb = 1 ' Button held down.
        Case 0: m.rb = _MouseButton(2)
    End Select
    If m.lb = -1 Then z1 = Timer: m.clkcnt = m.clkcnt + 1
End Sub
Shoot first and shoot people who ask questions, later.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Double slit experiment vince 7 1,649 07-18-2024, 11:06 PM
Last Post: Pete
  Click Away Balls bplus 6 1,553 05-16-2022, 01:04 PM
Last Post: Dav

Forum Jump:


Users browsing this thread: