Post

Replies

Boosts

Views

Activity

Capture all inbuilt trackpad events and cancel some touch events
I'm trying to capture all trackpad events at OS level and disable few of them - say the ones in left half of trackpad. Following this question, I could level listen to events in current window view with following code. final class AppKitTouchesView: NSView { override init(frame frameRect: NSRect) { super.init(frame: frameRect) // We're interested in `.indirect` touches only. allowedTouchTypes = [.indirect] // We'd like to receive resting touches as well. wantsRestingTouches = true } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } private func handleTouches(with event: NSEvent) { // 1. Change `in` parameter to listen events at OS level // 2. Disable all events with `touch.normalizedPosition.x < 0.5` let touches = event.touches(matching: .touching, in: self) } override func touchesBegan(with event: NSEvent) { handleTouches(with: event) } override func touchesEnded(with event: NSEvent) { handleTouches(with: event) } override func touchesMoved(with event: NSEvent) { handleTouches(with: event) } override func touchesCancelled(with event: NSEvent) { handleTouches(with: event) } } I'd to accomplish two things further. Change in parameter to listen events at OS level Disable all touch events on some condition - say touch.normalizedPosition.x < 0.5
0
0
428
Jul ’24