Sciguy77
Sciguy77

Reputation: 349

Receiving double-click event

I've been searching the Apple docs and the only function I could find pertaining to a double click just returned the acceptable time between clicks for it to be considered a double click.

Can someone please show me an example of a double click event?

Upvotes: 6

Views: 6764

Answers (3)

Yuji
Yuji

Reputation: 34185

Note also that some NSControl has setDoubleAction: so that the selector registered via setDoubleAction: is sent to the target. See the official documentations of

Upvotes: 2

NSResponder
NSResponder

Reputation: 16861

See NSEvent's -clickCount method.

Upvotes: 4

Jeremy W. Sherman
Jeremy W. Sherman

Reputation: 36143

Override the NSResponder method -mouseUp: and check the supplied event's clickCount. If clickCount == 2, then you're looking at a double-click. If it's 1, then a single click. 0, then they waited long enough between mouse down and mouse up that the system decided it's not a click, just distinct down then up events.

- (void)mouseUp:(NSEvent *)event
{
    NSInteger clickCount = [event clickCount];
    if (2 == clickCount) [self handleDoubleClickEvent:event];
}

This assumes the object handling the click is part of the responder chain. If not, you'll have to get your events another way, like subclassing NSApplication or NSWindow and overriding -sendEvent: to intercept the appropriate event before it gets passed along any further.

Upvotes: 16

Related Questions