A Swift wrapper for macOS MultitouchSupport private framework, providing easy access to raw trackpad touch data.
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/akinazuki/MultitouchKit", from: "1.0.0")
]Or in Xcode:
- File → Add Package Dependencies
- Enter the repository URL
- Add to your target
dependencies: [
.package(path: "../MultitouchKit")
]import MultitouchKit
// Start monitoring single-touch events
MultitouchManager.shared.startMonitoring(
onTouchMove: { touch in
print("Touch at: \(touch.percentX)%, \(touch.percentY)%")
print("Pressure: \(touch.pressure)")
print("State: \(touch.state)")
}
)
// Stop monitoring when done
MultitouchManager.shared.stopMonitoring()import MultitouchKit
MultitouchManager.shared.startMonitoring(
onTouchMove: { touch in
// Single finger touch
print("Single touch: (\(touch.normalizedX), \(touch.normalizedY))")
},
onMultiTouch: { touches in
// Multiple fingers
print("Multi-touch: \(touches.count) fingers")
for (index, touch) in touches.enumerated() {
print(" Finger \(index): \(touch.percentX)%, \(touch.percentY)%")
}
}
)public struct TouchData {
// Normalized coordinates (0.0 - 1.0)
public let normalizedX: Float // 0=left, 1=right
public let normalizedY: Float // 0=top, 1=bottom
// Velocity
public let velocityX: Float
public let velocityY: Float
// Pressure (0.0 - 1.0+)
public let pressure: Float
// Touch state
public let state: TouchState
// Identifiers
public let fingerID: Int32
public let pathIndex: Int32
// Convenience properties
public var percentX: Int // 0-100
public var percentY: Int // 0-100
public var isLeftSide: Bool
public var sideDescription: String // "LEFT" or "RIGHT"
}public enum TouchState: UInt32 {
case TouchStateNotTracking = 0
case TouchStateStartInRange = 1
case TouchStateHoverInRange = 2
case TouchStateMakeTouch = 3
case TouchStateTouching = 4
case TouchStateBreakTouch = 5
case TouchStateLingerInRange = 6
case TouchStateOutOfRange = 7
}- macOS 11.0+
- Swift 5.9+
- Xcode 15.0+
MultitouchKit links to /System/Library/PrivateFrameworks/MultitouchSupport.framework and provides:
- Device enumeration and filtering (excludes Magic Mouse, older devices)
- Touch event callbacks with raw trackpad data
- Automatic coordinate normalization and conversion
- Thread-safe event dispatching
This library uses undocumented private APIs. Use at your own risk. The API may change or be removed in future macOS versions without notice.