Skip to content

akinazuki/MultitouchKit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

MultitouchKit

A Swift wrapper for macOS MultitouchSupport private framework, providing easy access to raw trackpad touch data.

Installation

Swift Package Manager

Add to your Package.swift:

dependencies: [
    .package(url: "https://github.com/akinazuki/MultitouchKit", from: "1.0.0")
]

Or in Xcode:

  1. File → Add Package Dependencies
  2. Enter the repository URL
  3. Add to your target

Local Development

dependencies: [
    .package(path: "../MultitouchKit")
]

Usage

Basic Example

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()

Multi-Touch Example

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)%")
        }
    }
)

Touch Data Properties

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"
}

Touch States

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
}

Requirements

  • macOS 11.0+
  • Swift 5.9+
  • Xcode 15.0+

How It Works

MultitouchKit links to /System/Library/PrivateFrameworks/MultitouchSupport.framework and provides:

  1. Device enumeration and filtering (excludes Magic Mouse, older devices)
  2. Touch event callbacks with raw trackpad data
  3. Automatic coordinate normalization and conversion
  4. Thread-safe event dispatching

Disclaimer

This library uses undocumented private APIs. Use at your own risk. The API may change or be removed in future macOS versions without notice.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors