A robust, high-performance C++ library for simulating Mouse and Keyboard input on Windows.
Designed for automation, game scripting, and macro creation, InputUtilities provides a safe wrapper around the Windows SendInput API. It features a unique Safemode system that tracks active inputs and automatically releases them upon destruction or error, preventing “stuck keys” or “stuck mouse buttons.”
SendInput with minimal overhead.One of the key features of this library is the toggleable Safemode.
false (Default) — Maximum PerformanceSendInput.Ctrl), that key will remain physically “pressed” in Windows until you press it again manually.true — Safety Firstunordered_set (Hash Map) using O(1) operations.reset() is called automatically to release all held keys.// 1. Performance Mode (Default) - Zero overhead
InputUtilities inputFast;
// 2. Safemode - Tracks inputs, auto-releases on crash/exit
InputUtilities inputSafe(true);
This is a header-only compatible library structure.
InputUtilities.h / .cppInputUtilitiesCore.h / .cppInputData.hInputUtilities.h in your main file.User32.lib (Standard in Visual Studio).This example combines smooth mouse movement with delayed typing to mimic a real user filling out a form.
#include "InputUtilities.h"
int main() {
InputUtilities input(true); // Safemode ON recommended for complex scripts
// 1. Move mouse smoothly to coordinates (800, 400)
// Take 20 steps, with 5ms delay between steps.
input.SetCursorPos(800, 400, 20, 5, true);
// 2. Click the text box (50ms hold time)
input.leftClick(50);
// 3. Type a username with natural variance
// 75ms delay between keystrokes makes it look human.
input.typeStr(L"PlayerOne_123", 75);
// 4. Press Enter
input.vKey(VK_RETURN, 50);
return 0;
}
Many DirectX games (FPS/MMO) ignore standard Windows keys. This example uses Scan Codes (scKey) which simulate hardware interrupts, and interacts with Side Mouse Buttons.
#include "InputUtilities.h"
int main() {
InputUtilities input(true);
// Press 'W' using Hardware Scan Code (Simulates physical keyboard)
// Hold for 2 seconds (Running forward)
input.scKey(L'w', 2000);
// While running, press Mouse Side Button 1 (e.g., Melee attack)
input.extraClick(XBUTTON1, 100);
// Press Spacebar (Jump) via Scan Code
input.scKey(L' ', 50);
return 0;
}
For scenarios requiring raw speed, disable Safemode to skip the tracking logic overhead.
#include "InputUtilities.h"
int main() {
// Disable Safemode for maximum throughput
InputUtilities input(false);
// Spam Left Click as fast as the OS can handle
for(int i = 0; i < 1000; ++i) {
input.leftClick(0); // 0ms hold time = Instant tap
Sleep(10); // Optional regulation
}
return 0;
}
Sometimes you need to hold a key while performing other actions. This demonstrates how Safemode saves you from stuck keys.
#include "InputUtilities.h"
int main() {
{
InputUtilities input(true);
// 1. Hold 'Shift' (e.g., to select text or sprint)
input.vKeyDown(VK_SHIFT);
// 2. Perform other actions while Shift is held
input.vKey(VK_RIGHT, 50);
// ... Imagine an exception occurs here or the program crashes ...
// Because Safemode is ON, the destructor is called here.
// It detects VK_SHIFT is still down and releases it automatically.
}
return 0;
}
InputUtilities (High-Level Wrapper)leftClick(ms), rightClick(ms), middleClick(ms)extraClick(button, ms): Supports XBUTTON1 and XBUTTON2.vKey(code, ms): Standard Virtual Key press.scKey(char, ms): Scan Code press (Hardware simulation).unicodeKey(char, ms): Unicode character injection.typeStr(string, delay): Types a full string using Unicode.scTypeStr(string, delay): Types a full string using Scan Codes.InputUtilitiesCore (Low-Level Control)SetCursorPos(x, y, abs): Instant movement.SetCursorPos(x, y, steps, delay, abs): Smooth interpolated movement.MouseEvent(flags, data): Raw mouse event injection.vKeyDown/Up, scKeyDown/Up, unicodeKeyDown/Up: Manual state control.MouseWheelRoll(scrolls, direction, ...): Precise scrolling control.WinUser.h)This project is open-source. Feel free to use it in your personal or commercial projects.