AI Virtual Mouse is a Human-Computer Interaction (HCI) prototype that allows users to control their Windows cursor with sub-millimeter precision using hand gestures.
Unlike standard gesture scripts that suffer from lag and jitter, this project focuses on high-performance stability. It utilizes Coordinate Interpolation for screen mapping and direct Win32 API calls (ctypes) for zero-latency cursor movement, bypassing the overhead of traditional automation libraries like PyAutoGUI.
ctypes.windll.user32 to interface directly with the Windows OS for instant cursor response.cv2) - Image processing and canvas rendering.ctypes) - For DPI awareness and hardware-level mouse events.git clone [https://github.com/prakharsaxena230706-hub/AI-Virtual-Mouse.git](https://github.com/prakharsaxena230706-hub/AI-Virtual-Mouse.git)
cd AI-Virtual-Mouse
pip install opencv-python mediapipe numpy
python main.py
| Gesture | Action | Visual Feedback |
|---|---|---|
| Index Finger Moving | Move Cursor | 🟢 Green Pointer |
| Pinch (Index + Thumb) | Left Click | 🔴 Red Tips + “CLICK!” Text |
| Exit | Close App | Press ESC Key |
Issue: Mapping the camera’s 4:3 aspect ratio directly to a 16:9 monitor makes the edges physically hard to reach.
Solution: Implemented np.interp (Linear Interpolation) to map a central “Active Zone” (Frame Margin) to the full screen resolution. This creates a virtual sensitivity multiplier.
Issue: Raw landmark data from ML models is noisy, causing the cursor to shake.
Solution: Applied a smoothing factor (damping) to the coordinates:
Current_Pos = Prev_Pos + (Target_Pos - Prev_Pos) / Smoothing_Factor
Issue: Windows High-DPI displays (125% zoom) cause Python to miscalculate screen coordinates.
Solution: Enforced ctypes.windll.shcore.SetProcessDpiAwareness(1) to retrieve the true physical resolution of the monitor.
Contributions are welcome! Feel free to open an issue or submit a pull request for features like “Right Click” gestures or “Scroll” functionality.
Developed by Prakhar Saxena