Kernel-mode mouse injection prototype. A Windows kernel driver captures the mouse input callback from MouClass/MouHID and injects synthetic mouse events (moves, button presses) that appear as real hardware input. A Python GUI controller talks to the driver via IOCTL.
- Overview
- Architecture
- Prerequisites
- Required Installations
- Build
- Driver Signing
- Install & Run
- Project Structure
- How It Works
- Troubleshooting
- Unload Driver
InputHog lets you programmatically move the mouse and simulate button actions from user-mode without relying on SendInput or hooks. The driver injects events at the kernel level, so they are indistinguishable from physical mouse input to applications and games.
Use cases: Automation, testing, accessibility, or any scenario where low-level mouse control is needed.
Limitations:
- Requires Administrator privileges (driver load + controller)
- Requires test signing (or a proper code-signing certificate)
- MouHID only: Needs a USB mouse. PS/2 (i8042prt) can be added later.
- x64 only (32-bit kernel support dropped in WDK 10)
┌─────────────────────────────────────┐
│ InputHogControl.exe (Python/Tk) │ User mode
│ - GUI: patterns, status, tests │
│ - client.py: DeviceIoControl │
└──────────────┬──────────────────────┘
│ \\.\InputHog (CreateFile + IOCTL)
▼
┌─────────────────────────────────────┐
│ InputHog.sys (kernel driver) │ Kernel mode
│ - Creates \Device\InputHog │
│ - Handles IOCTL_INPUT_HOG_* │
│ - Injects via MouClass callback │
└──────────────┬──────────────────────┘
│ MOUSE_INPUT_DATA
▼
┌─────────────────────────────────────┐
│ MouClass / MouHID │ Windows mouse stack
│ (system mouse drivers) │
└─────────────────────────────────────┘
Data flow:
- User clicks a button in the GUI (e.g. "Square").
- Controller sends an IOCTL with
MOUSE_MOVE_REQUESTorMOUSE_INPUT_REQUEST. - Driver calls the captured
MouClasscallback withMOUSE_INPUT_DATA. - Windows delivers the input as if the physical mouse moved.
- OS: Windows 10 or 11 (x64)
- Hardware: USB mouse (required for MouHID)
- BIOS / firmware:
- Secure Boot must be disabled (test signing is blocked otherwise)
- Memory Integrity (HVCI) is often required off as well (Settings → Privacy & Security → Windows Security → Device security → Core isolation)
Install Visual Studio 2022 or Visual Studio 2026 (Insiders) with:
- Desktop development with C++ workload
- C++ ATL for latest build tools (if prompted)
- Windows 10 SDK or Windows 11 SDK (matching your target)
For VS 2026 Insiders, ensure CMake 4.2+ for Visual Studio 18 2026 generator support.
Download: Visual Studio
Install the standalone WDK from Microsoft. The WDK available through the VS Installer alone may be missing kernel-mode headers.
- Go to Download the WDK
- Download Windows Driver Kit (WDK) for your Windows version
- Run the installer
- Optionally install WDK Visual Studio extension if you want VS integration
- Ensure kernel-mode components are installed:
C:\Program Files (x86)\Windows Kits\10\Include\<version>\km\ntddk.hmust exist
The WDK provides MakeCert, SignTool, and kernel headers used for driver build and test signing.
Needed if you build the driver with CMake.
- Minimum: 3.18 (for presets)
- Recommended: 3.28+ (for VS 2026 generator:
Visual Studio 18 2026)
Download from cmake.org or install via winget install Kitware.CMake.
Required for the controller app and PyInstaller.
- Minimum: Python 3.9
- Install from python.org or
winget install Python.Python.3.12 - Ensure
pythonandpipare onPATH
If you use Cursor or VS Code:
- CMake Tools (
ms-vscode.cmake-tools) for configure/build from the editor cmake.useCMakePresetsandcmake.defaultConfigurePresetare set in.vscode/settings.json
Option A: CMake + presets (recommended)
# From repo root. Uses CMakePresets.json (Visual Studio 18 2026)
.\build-driver.ps1 -Config Debug
# or
.\build-driver.ps1 -Config Release- Stops the InputHog service first (so the
.syscan be overwritten) - Configures with
cmake --preset x64-debugorx64-release - Output:
build\driver\Debug\InputHog.sysorbuild\driver\Release\InputHog.sys
Option B: CMake from IDE
- Open the folder in Cursor/VS Code with CMake extension
- Select preset: CMake: Select Configure Preset →
x64-debugorx64-release - CMake: Configure
- CMake: Build
Option C: Visual Studio solution
- Open
InputHog.sln - Select x64, Release or Debug
- Build Solution (F7)
Output: driver\bin\x64\Release\InputHog.sys (or Debug)
cd controller
pip install -r requirements.txt
.\build.batOutput: controller\dist\InputHogControl.exe
Debug build (console + tracebacks):
cd controller
.\build-debug.batOutput: controller\dist\InputHogControl-Debug.exe
Windows will not load an unsigned kernel driver even with test signing enabled on some systems. Use sign-driver.ps1 to create a test certificate and sign the driver.
Run as Administrator:
.\sign-driver.ps1This script:
- Creates
InputHogTest.cer(if it doesn't exist) - Installs the cert in Trusted Root and Trusted Publishers
- Signs the driver with SignTool (
/fd SHA256)
It looks for the driver at:
build\driver\InputHog.sysbuild\driver\Debug\InputHog.sysbuild\driver\Release\InputHog.sysC:\InputHog\InputHog.sysdriver\bin\x64\Release\InputHog.sysdriver\bin\x64\Debug\InputHog.sys
Or pass explicitly: .\sign-driver.ps1 -DriverPath "C:\path\to\InputHog.sys"
Run as Administrator from the repo root:
# First time: enable test signing (reboot if prompted)
.\setup-windows.ps1 -EnableTestSigning
# After reboot (if needed): install driver and launch app
.\setup-windows.ps1What setup-windows.ps1 does:
- Enable test signing (if
-EnableTestSigning):bcdedit /set testsigning on(reboot required if changed) - Find driver: Checks
build\driver\Debug,build\driver\Release, etc. - Copy to
C:\InputHog\InputHog.sys(avoids OneDrive/sync path issues that cause error 123) - Create/update service: Stops and removes old
InputHogservice, creates new one with correct path - Start driver
- Launch
InputHogControl.exe(unless-SkipAppLaunch)
Parameters:
-EnableTestSigning— turn on test signing-SkipAppLaunch— install driver only, don't start the GUI-TestSigningOnly— enable test signing only, skip driver install-DriverPath "path"— use a specific driver file
-
Enable test signing (once):
bcdedit /set testsigning onReboot.
-
Sign the driver (if needed):
.\sign-driver.ps1 -
Run setup:
.\setup-windows.ps1 -
Or run the app directly (right-click → Run as administrator):
controller\dist\InputHogControl.exe
- Open Paint
- Run
InputHogControl.exeas Administrator - Click Square, Circle, or Triangle
- The cursor should move without touching the mouse
- Use Refresh for driver status (callback found, request counters, NTSTATUS)
InputHog can record mouse movements, clicks, and keyboard input, then replay them or export as a standalone Python script.
- Record: Click Record, move the mouse, click, type—then Stop
- Save: Saves to
.json(portable, editable) - Load: Load a previously saved recording
- Play: Replays the current recording (mouse via driver, keyboard via
keybd_event) - Export as .exe: Creates a standalone
.pyscript that embeds the recording—run it as Administrator to play the macro without the main app. No extra dependencies beyond Python.
The exported script is self-contained (only needs ctypes, time) and works anywhere the InputHog driver is loaded. Keyboard events use user-mode keybd_event; mouse events use the kernel driver.
cpp-input-hog/
├── driver/ # Kernel driver
│ ├── driver.c # Device, IOCTL handling
│ ├── injection.c # MouClass callback injection
│ ├── injection.h
│ └── CMakeLists.txt
├── shared/
│ └── ioctl.h # IOCTL codes, request structs (driver + client)
├── controller/ # Python GUI
│ ├── app.py # Tkinter UI
│ ├── client.py # DeviceIoControl, IOCTL wrappers
│ ├── movements.py # Patterns (square, circle, drag, etc.)
│ ├── requirements.txt
│ ├── InputHogControl.spec
│ └── InputHogControl-Debug.spec
├── cmake/
│ └── FindWdk.cmake # WDK detection for CMake
├── CMakeLists.txt
├── CMakePresets.json # x64-debug, x64-release
├── InputHog.sln # Visual Studio solution
├── setup-windows.ps1 # Install driver + launch app
├── sign-driver.ps1 # Test-sign the driver
├── build-driver.ps1 # Build driver with CMake
└── README.md
- Device setup: Creates
\Device\InputHogand symbolic link\DosDevices\InputHog(\\.\InputHogfrom user mode). - Callback discovery: Locates the
MouClassmouse service callback by scanning device extensions ofMouHIDandMouClass. - IOCTLs:
IOCTL_INPUT_HOG_MOVE_MOUSE— relative move(dx, dy)IOCTL_INPUT_HOG_MOUSE_INPUT— move + button flags (e.g. right down/up)IOCTL_INPUT_HOG_GET_STATUS— injection status, counts, NTSTATUS
- Injection: Fills
MOUSE_INPUT_DATAand calls the captured callback so Windows processes the event as real mouse input.
- Uses
CreateFileon\\.\InputHogandDeviceIoControlto send IOCTLs client.pymirrorsshared/ioctl.h(IOCTL codes, struct layouts)movements.pyprovides patterns (square, circle, triangle, line, random drag with right-button)
Driver is not signed or certificate is not trusted.
- Run
.\sign-driver.ps1as Administrator - Run
.\setup-windows.ps1again
Driver path is invalid or inaccessible (often OneDrive/sync paths). setup-windows.ps1 copies the driver to C:\InputHog\InputHog.sys to avoid this.
Secure Boot blocks test signing. Disable Secure Boot in BIOS/UEFI, then:
bcdedit /set testsigning onReboot.
Turn off Core Isolation: Settings → Privacy & Security → Windows Security → Device security → Core isolation details → disable Memory integrity.
WDK kernel-mode headers are missing. Install the standalone WDK from Microsoft and ensure km headers exist under C:\Program Files (x86)\Windows Kits\10\Include\*\km\.
You need Visual Studio 2026 or CMake that supports it. Alternatives:
- Install VS 2026 Insiders, or
- Change
CMakePresets.jsonto"generator": "Visual Studio 17 2022"and use VS 2022
The driver file is locked. Do the following:
- Stop the driver:
sc stop InputHog - Close the controller app if it is running
- Rebuild with
.\build-driver.ps1
The driver was linked with user-mode libraries. Ensure CMAKE_C_STANDARD_LIBRARIES is cleared in driver/CMakeLists.txt (already done in this project).
Run the controller as Administrator.
Errors are written to inputhog_debug.log beside the executable. Use the debug build for console output: controller\dist\InputHogControl-Debug.exe.
sc stop InputHog
sc delete InputHogcd controller
python app.pyRun as Administrator.