Mouse Down (NSEvent in Swift 2)

As I continue adding features for my upcoming app I’m starting to work with NSEvents to add actions to user interaction. I’ve been amazed at how fast is to do this in Swift. 

For instance, detecting where the user presses a button in your window, and then converting it to the coordinate system of a view is extremely easy. Just type the following within your NSView class:

override func mouseDown(theEvent : NSEvent) {

        Swift.print(“Original: \(theEvent.locationInWindow)”)

        let convertedPoint = self.convertPoint(theEvent.locationInWindow, fromView: theEvent.window?.contentView)

        Swift.print(“Tuned: \(convertedPoint)”)

 

    }

Easy as pie!

Feedback, send it @MarcMasVi on Twitter.