Control your computer's cursor using hand gestures via your webcam.
- Hand tracking - Detects and visualizes all 21 hand landmarks with skeleton overlay
- Cursor control - Move your cursor by moving your hand in front of the camera
- Pinch-to-click - Pinch your index finger and thumb together to click
- Dead zone - Small hand movements are ignored to reduce cursor jitter
- Fingertip labels - Each fingertip is labeled on the camera feed (thumb, index, middle, ring, pinky)
- The palm center is calculated by averaging 5 palm landmarks (wrist + base of each finger)
- Palm position is mapped from camera coordinates to screen coordinates to move the cursor
- A dead zone threshold prevents jittery cursor movement when your hand is still
- Pinch detection measures the distance between the index fingertip and thumb tip — when close enough, a click is triggered
- Python 3.10+
- A webcam
-
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate -
Install dependencies:
pip install opencv-python mediapipe pyautogui
-
Download the MediaPipe hand landmarker model and place it in the project root:
-
On macOS, grant Accessibility permissions to your terminal/Python so
pyautoguican control the cursor:- System Settings > Privacy & Security > Accessibility
python main.py- Move your hand to control the cursor
- Pinch index finger + thumb to click
- Press
qto quit
You can tweak these values at the top of main.py:
| Variable | Default | Description |
|---|---|---|
cv2.VideoCapture(0) |
0 |
Camera index (try 1 or 2 if default doesn't work) |
DEAD_ZONE |
10 |
Minimum cursor movement threshold (higher = more stable, less responsive) |
PINCH_THRESHOLD |
30 |
Max distance between index and thumb to trigger a click (higher = easier to click) |