Catching double click in Cocoa OSX

Viewed 9904

NSResponder seems to have no mouse double click event. Is there an easy way to catch a double click?

7 Answers

The mouseDown: and mouseUp: methods take an NSEvent object as an argument with information about the clicks, including the clickCount.

An alternative to the mouseDown: + NSTimer method that I prefer is NSClickGestureRecognizer.

    let doubleClickGestureRecognizer = NSClickGestureRecognizer(target: self, action: #selector(self.myCustomMethod))
    doubleClickGestureRecognizer.numberOfClicksRequired = 2

    self.myView.addGestureRecognizer(doubleClickGestureRecognizer)
Related