Monitor Force Touch trackpad pressure on macOS with Python — integrate pressure data directly into pandas, matplotlib, PsychoPy experiments, ML models, and more.
pip install macos-trackpad-pressureNote: Install name is macos-trackpad-pressure, but import as trackpad_pressure:
from trackpad_pressure import PressureMonitor, start_gui_monitorfrom 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). Press Ctrl+C in the terminal to exit.
from trackpad_pressure import PressureMonitor
import signal
import sys
def on_pressure(pressure, stage):
print(f"Pressure: {pressure:.3f}, Stage: {stage}")
monitor = PressureMonitor(callback=on_pressure)
def exit_handler(signum, frame):
print("\nStopping monitor...")
monitor.stop()
sys.exit(0)
signal.signal(signal.SIGINT, exit_handler)
monitor.start()trackpad-pressure- Built-in Force Touch trackpads: MacBook Pro (2015+), MacBook Air (2018+)
- Magic Trackpad 2: Should work (tested on some systems)
- Normalized range: Pressure values are normalized from 0.0 (no pressure) to 1.0 (maximum pressure)
- Event-driven: Callbacks fire when pressure changes, not at a fixed rate. Frequency depends on hardware and OS
- Window focus: The monitor window must be in focus to receive pressure events (this is a macOS security feature)
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.
For more information on Force Touch behavior, see Apple's Developer Documentation.
- Python 3.7+
- Tested on Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12
- macOS 10.11+ with Force Touch trackpad
- Python 3.7+
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
See examples/simple_callback.py for a minimal example.
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')See examples/csv_export.py for a complete example with signal handling.
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()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()examples/psychopy_experiment.py- PsychoPy integration for experimentsexamples/midi_control.py- Pressure → MIDI controlexamples/pressure_brush.py- Real-time pressure visualization
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.stop(): Stop monitoring and close GUI window (if open).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(monitor=None)Launch the GUI pressure monitor window.
Parameters:
monitor(PressureMonitor, optional): Pass a PressureMonitor instance to enable callbacks alongside GUI display.
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 monitor window is in focus (macOS only sends events to focused windows)
- Check terminal for error messages
- Verify you're pressing on the trackpad, not an external mouse
- Ensure you have a Force Touch trackpad (not all MacBooks have them)
Import errors?
- Make sure you installed with
pip install macos-trackpad-pressure - Import as
from trackpad_pressure import ...(notmacos_trackpad_pressure)
Issues and pull requests welcome on GitHub.
See CHANGELOG.md for version history.
MIT
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.