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
Metadata
Release files for macos-trackpad-pressure 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| macos_trackpad_pressure-0.1.2.tar.gz | 11.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| macos_trackpad_pressure-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.9 kB
Release files / macos_trackpad_pressure-0.1.2.tar.gz
| Download URL | macos_trackpad_pressure-0.1.2.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
76a6538934b6138f6ccc382604cf07c6c1d5f91ef01017b0c4ccc7afc7d7a99e
|
|
BLAKE2b-256 checksum How to use checksums |
fdf9989d03e8fc55b3fd43ee0ab1304a2013098dfc268378201c24bd7765963b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / macos_trackpad_pressure-0.1.2-py3-none-any.whl
| Download URL | macos_trackpad_pressure-0.1.2-py3-none-any.whl |
|---|---|
| Size | 10.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
687f6d380ec334abde6843bcf37db325d402b04e46a5281d339e9bca3b043b8f
|
|
BLAKE2b-256 checksum How to use checksums |
5573ab281aaae5f1909ed68faaf1bf1a905dbf431642cd338f0281e1439f53db
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for macos-trackpad-pressure 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.