Control your computer mouse with hand gestures using your webcam. No need to touch anything - just move your hand!
This program lets you control your mouse cursor, click, scroll, and adjust volume using simple hand gestures. It uses your webcam to track your hand movements in real-time.
- Python 3.7 or newer
- A webcam (built-in or USB)
- Windows (some features work on other systems too)
- Download or clone this project:
git clone https://github.com/asheint/AI-Virtual-Mouse.git
cd AI-Virtual-Mouse- Install the required packages:
pip install -r requirements.txtThat's it! You're ready to go.
- Run the program:
python AiVirtualMouseProject.py-
A window will open showing your camera feed. You'll see your hand being tracked with dots and lines.
-
Make hand gestures to control your mouse:
Mouse movement: Point with just your index finger Left click: Put up index and middle finger, then bring them close together Right click: Put up index, middle, and ring finger, then bring them close Scroll: Put up index finger and pinky, then move your index finger up/down Drag and drop: Put up thumb and index finger, then move around Volume control: Put up thumb and pinky, change distance between them
- Press 'q' to quit
- Use good lighting
- Keep your hand 1-2 feet from the camera
- Try to have a plain background behind your hand
- Make clear, distinct finger positions
- If the camera doesn't work, the program will automatically try different camera numbers (0, 1, 2)
The program detects which fingers are up (1) or down (0). For example:
[0,1,0,0,0]means only index finger is up → moves mouse[0,1,1,0,0]means index and middle up → ready to click[1,0,0,0,1]means thumb and pinky up → volume control
Camera not found: Make sure no other programs are using your camera. The program tries camera indices 0, 1, 2 automatically.
Volume control not working: Try running as administrator.
Gestures not detected well: Improve lighting and use a plain background.
Package installation errors: Use a virtual environment or update pip.
AiVirtualMouseProject.py- Main programHandTrackingModule.py- Hand detection coderequirements.txt- List of packages neededREADME.md- This file
You can edit these values in AiVirtualMouseProject.py:
wCam, hCam = 640, 480 # Camera resolution
frameR = 100 # Mouse control area border
smoothening = 7 # How smooth mouse movement is
scroll_sensitivity = 20 # How sensitive scrolling isFeel free to improve this project! Just fork it, make your changes, and submit a pull request.
MIT License - you can use this code however you want.
If this project helped you, consider buying me a coffee! ☕
Made by Ashen Thilakarathna - Hope you find it useful!
