A hand-tracking tool that uses your webcam to detect a pinch gesture (thumb and index finger touching) and presses the spacebar — handy for pausing/playing media hands-free.
- Captures webcam video with OpenCV
- Uses MediaPipe's
HandLandmarker(Tasks API) to detect hand landmarks in real time - Measures the distance between the thumb tip and index finger tip
- When the distance drops below a threshold (pinch detected), simulates a spacebar press via
pynput
- Python 3.9+
- A webcam
- An internet connection the first time you run it (to download the ~10MB hand landmark model)
git clone https://github.com/Jayavisaag/pinch-to-pause.git
cd pinch-to-pause
pip install -r requirements.txtpython main.py- On first run, it downloads
hand_landmarker.task(the detection model) into the project folder — this only happens once. - A window will open showing your webcam feed with hand landmarks drawn on it.
- Pinch your thumb and index finger together to trigger a spacebar press.
- Press
qto quit.
- The pinch distance threshold (default: 40 pixels) can be tuned in
main.pyif it's too sensitive or not sensitive enough. - Only tracks one hand at a time (
num_hands=1). - On macOS, you may need to grant your terminal/IDE Accessibility and Camera permissions (System Settings → Privacy & Security) for the keypress simulation and webcam access to work.
- This project uses MediaPipe's current Tasks API (
HandLandmarker), not the oldermp.solutionsAPI, which Google removed from recent MediaPipe releases.