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.