Control your mouse cursor using your index finger and click by pinching!
- Cursor Control: Move your index finger to control the mouse cursor
- Click Detection: Pinch your thumb and index finger together to click
- Smooth Movement: Built-in smoothing to reduce jittery cursor movement
- Visual Feedback: See your hand skeleton and finger tracking in real-time
-
Install Python dependencies:
pip install -r requirements.txt
-
For Linux users, you may need additional permissions for mouse control:
# Install xdotool sudo apt-get install xdotool
Run the program:
python virtual_mouse.py- Move cursor: Move your index finger around
- Click: Pinch your thumb and index finger together
- Quit: Press 'q' on the keyboard
- Camera Capture: Uses OpenCV to capture video from your webcam
- Hand Detection: MediaPipe detects your hand and tracks 21 landmarks
- Finger Tracking: Monitors the index finger tip position (landmark #8)
- Coordinate Mapping: Converts camera coordinates to screen coordinates
- Smoothing: Applies exponential smoothing to reduce jitter
- Gesture Recognition: Detects pinch gesture (thumb-index distance < threshold)
- Mouse Control: PyAutoGUI moves the cursor and triggers clicks
You can adjust these parameters in the code:
smoothing(line 18): Higher = smoother but more lag (default: 7)frame_reduction(line 21): Increases control area (default: 100)min_detection_confidence(line 43): Hand detection sensitivity (default: 0.7)- Pinch threshold in
is_pinching()(line 30): Distance for click (default: 0.05)
- Lighting: Good lighting helps with hand detection
- Background: Plain backgrounds work better than cluttered ones
- Distance: Keep your hand 1-2 feet from the camera
- Calibration: Adjust
frame_reductionif the cursor doesn't reach screen edges - Smoothing: Increase
smoothingvalue if cursor is too jittery
Cursor is jittery:
- Increase the
smoothingvalue (try 10-15)
Cursor doesn't reach screen edges:
- Decrease
frame_reductionvalue or adjust the interp ranges
Hand not detected:
- Improve lighting
- Lower
min_detection_confidenceto 0.5 - Make sure your hand is clearly visible
Clicks not registering:
- Increase the pinch threshold (try 0.07 instead of 0.05)
- Make a more deliberate pinching motion
- Python 3.7+
- Webcam
- The libraries in requirements.txt
Ideas to extend this project:
- Right-click with different gestures
- Scroll by swiping
- Drag-and-drop functionality
- Multi-finger gestures
- Calibration mode for different screen sizes
- Virtual keyboard integration