AI Virtual Mouse is a Python application that enables controlling the mouse cursor with hand gestures captured via a webcam.
It leverages MediaPipe Hands for landmark detection, OpenCV for video processing, and PyAutoGUI for system-level mouse control.
- Real-time hand detection and landmark tracking with MediaPipe
- Cursor movement mapped to index finger tip position
- Gesture-based controls:
- Move Cursor → move index finger
- Left Click → pinch index finger & thumb together
- Right Click → pinch middle finger & thumb
- Scroll Up/Down → vertical hand gestures
- Multi-hand support (detects left vs right hand)
- Configurable gesture mapping for customization
Install them with:
pip install opencv-python mediapipe pyautogui numpy-
Clone the repository:
git clone https://github.com/yourusername/ai-virtual-mouse.git cd ai-virtual-mouse -
Run the application:
python main.py
-
Place your hand in view of the webcam:
- Move your index finger → cursor moves
- Pinch index & thumb → left click
- Pinch middle & thumb → right click
- Move hand up/down with open palm → scroll
-
Press
qto quit.
- Sensitivity, smoothing, and gesture mappings can be adjusted in
config.py. - Debug overlays (landmarks, FPS, gesture labels) can be enabled by setting
draw_landmarks=Truewhen initializingHandTracker.
ai_virtual_mouse/
├── main.py # Entry point
├── hand_tracker.py # MediaPipe hand detection wrapper
├── gesture_classifier.py # Maps landmarks → gestures
├── mouse_controller.py # Handles PyAutoGUI mouse actions
├── utils/ # Helper functions
└── tests/ # Unit & E2E tests
- Requires consistent lighting and clear webcam view of hands.
- Latency may increase on low-end hardware.
- Currently optimized for single-user interaction.
Contributions are welcome!
- Fork the repo
- Create a feature branch
- Submit a pull request
Built using Python, MediaPipe, OpenCV, and PyAutoGUI.