Trigger keyboard events from MacBook Pro accelerometer double-tap gesture.
This project is inspired by apple-silicon-accelerometer.
slap-trigger detects double-tap gestures using the built-in accelerometer on Apple Silicon MacBook Pro (M2+) and triggers keyboard shortcuts or shell commands. It's perfect for executing actions like paste, copy, or any custom key combination by simply double-tapping your MacBook.
- MacBook Pro with Apple Silicon (M2+) - Required for accelerometer sensor
- macOS 13+ - Required for macimu library
- Accessibility Permission - Required for keyboard simulation
# Using uv (recommended)
uv sync- Go to System Settings → Privacy & Security → Accessibility
- Enable your terminal app (Terminal, iTerm2, etc.)
- The program will warn you if permission is not granted
# Run with sudo (required for IMU access)
./run.shEdit config.json to customize your triggers:
{
"detector": {
"threshold": 1.02,
"min_interval_ms": 180,
"max_interval_ms": 220,
"cooldown_ms": 1500,
"debounce_ms": 60
},
"actions": [
{
"name": "paste",
"type": "keyboard",
"keys": ["command:left", "v"],
"enabled": true
}
]
}| Parameter | Description | Default |
|---|---|---|
threshold |
Acceleration threshold in g (1g = rest) | 2.0 |
min_interval_ms |
Minimum interval between taps (ms) | 50 |
max_interval_ms |
Maximum interval between taps (ms) | 500 |
cooldown_ms |
Cooldown after triggered double-tap (ms) | 750 |
debounce_ms |
Debounce window to ignore rapid peaks (ms) | 30 |
Trigger a keyboard shortcut:
{
"name": "my-action",
"type": "keyboard",
"keys": ["command:left", "c"],
"enabled": true
}Supported key formats:
- Letters:
a,b,c, ... - Numbers:
0,1,2, ... - Modifiers:
command:left,command:right,option:left,control,shift, ... - Special:
space,return,tab,delete,escape,f1-f12,left,right,up,down
Execute a shell command:
{
"name": "play sound",
"type": "cmd",
"cmd": ["afplay", "/path/to/sound.mp3"],
"enabled": true
}This feature requires Apple Silicon MacBook Pro (M2+). Older Macs don't have the required accelerometer.
- Open System Settings → Privacy & Security → Accessibility
- Enable your terminal app
- Some apps don't respond to single modifier key presses (e.g.,
option:right) - Try using combination keys like
command:left+v
Use ./run.sh wrapper instead of running directly with sudo. The wrapper uses launchctl asuser to switch back to your user context for keyboard simulation.
# Install dependencies
uv sync
# Run
./run.shslap_trigger/
├── cli.py # CLI entry point
├── config.py # Configuration loading
├── detector.py # Double-tap detection algorithm
└── keyboard.py # CGEvent keyboard simulation
MIT