Track Touch Events without app being focused - Swift

371 Views Asked by At

I made a simple project in Xcode to track the position of a touch event on a trackpad. I created a Custom View instance on my MainWindowController.xib for the class TrackpadController:

class TrackpadController: NSView {

override init(frame frameRect: NSRect) {
    super.init(frame: frameRect);
    self.acceptsTouchEvents = true
}

required init?(coder: NSCoder) {
    super.init(coder: coder)
}


override func touchesBeganWithEvent(event: NSEvent) {

    let touches = event.touchesMatchingPhase(.Began, inView: nil)

    for touch in touches {
        let touchPosition = touch.normalizedPosition
        Swift.print(touchPosition)
              }
}

}

The coordinates are printed in the console, but only if the cursor is over the view. I would like to be able to track the position on the trackpad when the app isn't focused. Any idea in how to get this would be great. Thanks.

0

There are 0 best solutions below