Get allowed unit distance between doubleclicks on macos

I’m writing a double click handler at the moment and I was wondering if anyone had code lying around for calculating the distance the mouse can move between double clicks? I have written the following code for windows:

Declare Function GetSystemMetrics Lib "User32" ( index as Integer ) as Integer Const SM_CXDOUBLECLK = 36 Const SM_CYDOUBLECLK = 37 mDoubleClickWidth = GetSystemMetrics(SM_CXDOUBLECLK) mDoubleClickHeight = GetSystemMetrics(SM_CYDOUBLECLK)

I just need the macos equivalent (as I’m not really a mac dev, I dont know where to look, had a quick google, cant find much).

I’d rather do it correctly if possible, I could always just code in 4 units as a default but I dont know if macos changes this depending on dpi/res etc.

Thanks in advance.

Use System.MouseX and System.MouseY to get the absolute position of the mouse in points (does not change with Retina mode).

[quote=303801:@Michel Bujardet]Edited 2 minutes ago by
I’m writing a double click handler at the moment and I was wondering if anyone had code lying around for calculating the [/quote]

That just returns me the position of the mouse, I want the system metric that defines how far the mouse can move between doubleclicks to actually register a doubleclick. If the mouse moved more than this metric between presses, it doesnt register a doubleclick.

Unless someone posts a declare that does the same thing as the Windows one, you can perfectly well track yourself the displacement of the mouse between the two clicks and decide to register a double click or not. I would suppose that such displacement cannot exceed something like 5 points.

Thanks Michel, I’m doing that already but if I’m going to spend the time implementing this, I’d like to get it 100% correct and not just guess at a number for it to break if someone with mobility issues is using the app and has a larger doubleclick spacing.

Did you try to get the actual values in Windows ? I would believe they are the same. I don’t want to be overly pessimistic, but usually, Mac declares are posted rather quickly. So far no peep.

I glanced myself into the Mac Developer library, and found nothing equivalent. That said it is a rich document. I may have overlooked it. See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/EventOverview/MouseTrackingEvents/MouseTrackingEvents.html

Yeah, my code above get the values ok, and they are set to 4 pixels.

Thanks for the link I’ll have read.

You can see the whole lot by looking HKEY_CURRENT_USER\Control Panel\Mouse in the registry if you are interested, but using the calls is preferable rather than reading out of the registry :slight_smile:

While there is a very obscure way to get the distance required between clicks, here’s a function that tells you if the event that triggered the MouseDown is a double click:

Private Sub IsDoubleClick()
  Declare Function NSClassFromString Lib "Foundation" (name As CFStringRef) As Ptr
  Declare Function sharedApplication Lib "AppKit" Selector "sharedApplication" (obj As Ptr) As Ptr
  Declare Function currentEvent Lib "AppKit" Selector "currentEvent" (obj As Ptr) As Ptr
  Declare Function type Lib "AppKit" Selector "type" (obj As Ptr) As UInteger
  Declare Function clickCount Lib "AppKit" Selector "clickCount" (obj As Ptr) As Integer
  Const NSEventTypeLeftMouseDown = 1
  
  Static NSApp As Ptr = sharedApplication(NSClassFromString("NSApplication"))
  
  Dim evt As Ptr = currentEvent(NSApp)
  If type(evt) = NSEventTypeLeftMouseDown Then
    Return clickCount(evt) = 2
  End If
End Sub

Thanks Joe, that code should enable me to do what I need.