Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Pinch to Pause

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.

How it works

  • 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

Requirements

  • Python 3.9+
  • A webcam
  • An internet connection the first time you run it (to download the ~10MB hand landmark model)

Installation

git clone https://github.com/Jayavisaag/pinch-to-pause.git
cd pinch-to-pause
pip install -r requirements.txt

Usage

python 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 q to quit.

Notes

  • The pinch distance threshold (default: 40 pixels) can be tuned in main.py if 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 older mp.solutions API, which Google removed from recent MediaPipe releases.

About

A Python utility that lets you trigger keyboard events using hand gestures. Powered by OpenCV and the MediaPipe Tasks API, it tracks your hand and simulates a spacebar keypress when you pinch your thumb and index finger together, creating a perfect hands-free "pause/play" button.

Topics

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages