Monitor and capture Force Touch trackpad pressure on macOS
Project description
macOS Trackpad Pressure Monitor
A Python library for monitoring Force Touch trackpad pressure on macOS.
Overview
This appears to be the first Python package for accessing trackpad pressure on macOS. Before this, you'd need to use Swift/Objective-C or write PyObjC bindings yourself.
For researchers and developers already working in Python, this means pressure data can now integrate directly with existing tools - pandas DataFrames, matplotlib plots, ML models, PsychoPy experiments, audio libraries, whatever you're already using.
Why This Exists
I needed trackpad pressure data for an HCI experiment studying cognitive load during gaming. The experiment setup required collecting pressure alongside eye tracking and EEG data - all using Python APIs.
Couldn't find a Python package for macOS trackpad pressure. Found Swift examples, but I didn't know Swift and had a tight deadline. Used PyObjC to quickly get something working for the experiment.
After finishing, a few other researchers asked for the code for their own projects. Figured I'd clean it up and put it on PyPI in case others need it too.
Installation
pip install macos-trackpad-pressure
Requirements
- macOS 10.11+ with Force Touch trackpad
- Python 3.7+
Quick Start
GUI Monitor
from trackpad_pressure import start_gui_monitor
start_gui_monitor()
A window will open - press on your trackpad with varying pressure to see real-time values (0.0 to 1.0).
With Callback Function
from trackpad_pressure import PressureMonitor
def on_pressure(pressure, stage):
print(f"Pressure: {pressure:.3f}, Stage: {stage}")
monitor = PressureMonitor(callback=on_pressure)
monitor.start()
Command Line
trackpad-pressure
Use Cases
This library integrates with Python's ecosystem for:
- HCI Research: Collect pressure data alongside other behavioral metrics
- Data Science: Export to pandas DataFrames, visualize with matplotlib/seaborn
- Machine Learning: Training data for gesture recognition models
- Creative Coding: Pressure-sensitive art with Processing/p5
- Music Production: MIDI control via pressure (using
mido,python-osc) - Game Development: Pressure controls in Pygame or Arcade
- Accessibility Tools: Custom input methods for assistive technology
- Education: Teaching input device concepts in Python courses
API Reference
PressureMonitor
PressureMonitor(callback=None)
Parameters:
callback(callable, optional): Function called when pressure changes. Receives(pressure: float, stage: int).
Methods:
start(gui=True): Start monitoring. Opens GUI window by default.current_pressure: Property returning current pressure value (0.0-1.0)current_stage: Property returning Force Touch stage (0, 1, or 2)
start_gui_monitor
start_gui_monitor(monitor=None)
Launch the GUI pressure monitor window.
Parameters:
monitor(PressureMonitor, optional): Pass a PressureMonitor instance to enable callbacks alongside GUI display.
Examples
Data Collection for Analysis
import time
import pandas as pd
from trackpad_pressure import PressureMonitor
data = []
def collect(pressure, stage):
data.append({
'timestamp': time.time(),
'pressure': pressure,
'stage': stage
})
monitor = PressureMonitor(callback=collect)
monitor.start()
# Later: convert to DataFrame
df = pd.DataFrame(data)
df.to_csv('pressure_data.csv')
Real-time Visualization
import matplotlib.pyplot as plt
from trackpad_pressure import PressureMonitor
pressures = []
def update_plot(pressure, stage):
pressures.append(pressure)
if len(pressures) % 10 == 0: # Update every 10 samples
plt.plot(pressures)
plt.pause(0.01)
monitor = PressureMonitor(callback=update_plot)
monitor.start()
Pressure-based Thresholds
from trackpad_pressure import PressureMonitor
def on_pressure(pressure, stage):
if pressure < 0.3:
print("Light touch")
elif pressure < 0.7:
print("Medium pressure")
else:
print("Heavy pressure")
monitor = PressureMonitor(callback=on_pressure)
monitor.start()
Troubleshooting
Getting 1.0 for every press?
- Requires a Force Touch trackpad (MacBook 2015+)
- Try pressing and holding with varying pressure, not just clicking
- Check System Preferences → Trackpad to ensure Force Touch is enabled
No pressure values appearing?
- Make sure the window is in focus
- Check terminal for error messages
- Verify you're pressing on the trackpad, not an external mouse
Technical Details
This package uses PyObjC to interface with macOS's Cocoa framework, specifically NSEvent.pressure() for accessing Force Touch sensor data. The API is intentionally simple: pass a callback function, get pressure values. No need to understand NSEvent or Cocoa frameworks unless you want to.
Contributing
Issues and pull requests welcome on GitHub.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file macos_trackpad_pressure-0.1.2.tar.gz.
File metadata
- Download URL: macos_trackpad_pressure-0.1.2.tar.gz
- Upload date:
- Size: 11.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76a6538934b6138f6ccc382604cf07c6c1d5f91ef01017b0c4ccc7afc7d7a99e
|
|
| MD5 |
e856a5d48776d1839096c12f4543ef24
|
|
| BLAKE2b-256 |
fdf9989d03e8fc55b3fd43ee0ab1304a2013098dfc268378201c24bd7765963b
|
File details
Details for the file macos_trackpad_pressure-0.1.2-py3-none-any.whl.
File metadata
- Download URL: macos_trackpad_pressure-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
687f6d380ec334abde6843bcf37db325d402b04e46a5281d339e9bca3b043b8f
|
|
| MD5 |
1a8fcc6df508db41a68577095b873771
|
|
| BLAKE2b-256 |
5573ab281aaae5f1909ed68faaf1bf1a905dbf431642cd338f0281e1439f53db
|