How to detect a click

2007-01-07 03:19:31 UTC

If you’ve ever written something that needs to simulate menu behavior, you’ve probably noticed that it would be nice to know, portably to future OS versions, how long you should wait before rejecting a mouse-down/mouse-up pair as not a click, as well as how far the user must move the mouse for it to not be a click.

The way to do this is:

EventTime clickTimeout;
HISize clickMaxDistance;
OSStatus err = HIMouseTrackingGetParameters(kMouseParamsSticky, &clickTimeout, &clickMaxDistance);

There is no Cocoa API for this.

3 Responses to “How to detect a click”

  1. Scott Stevenson Says:

    I think the duration thing should be handled globally, not on a per-application basis. That’s the point of the mouse panel in system preferences, right? Or am I misunderstanding you. I use NSEvent’s -clickCount.

  2. Peter Hosey Says:

    I’m sure it propagates to all applications, just like the HI scale factor and the double-click time.

    -clickCount tells you whether you have a single-, double-, triple-, or quadruple-click on your hands. Sticky testing means comparing a mouse-up event to the mouse-down before it.

    You must open the menu when

    • the timeout has elapsed without the mouse-up arriving (show menu by hold down), or
    • the mouse-up is within the max distance of the mouse-down (show menu by click).
  3. David Dunham Says:

    Wow, this is pretty obscure — nobody brought it up when I filed rdar://4556731, complaining about the lack for Cocoa. This looks like a perfectly good API. (I’ll have to see if it gives the same values I ended up using…)

Leave a Reply

Do not delete the second sentence.