usehid-core
Cross-platform virtual HID device library for AI agents. Control mouse, keyboard, and gamepad programmatically.
Features
- 🖱️ Virtual Mouse - Move, click, double-click, scroll
- ⌨️ Virtual Keyboard - Type text, press keys, key combinations
- 🎮 Virtual Gamepad - Joysticks, buttons, triggers
- 🤖 Agent API - JSON-based interface for LLM tool-calling
- 🦀 Pure Rust - Safe, fast, no unsafe dependencies
Platform Support
| Platform | Mouse | Keyboard | Gamepad | Backend |
|---|---|---|---|---|
| macOS | ✅ | ✅ | ⚠️ | CGEvent |
| Linux | ✅ | ✅ | ✅ | uhid |
| Windows | ✅ | ✅ | ⚠️ | SendInput |
Quick Start
Add to your Cargo.toml:
[]
= "0.1"
For AI Agents (Recommended)
use AgentHID;
let mut agent = new;
// Mouse actions
agent.execute_json;
agent.execute_json;
agent.execute_json;
// Keyboard actions
agent.execute_json;
agent.execute_json;
agent.execute_json;
Direct Device Control
use ;
// Mouse
let mut mouse = new;
mouse.create?;
mouse.move_by?;
mouse.click?;
mouse.scroll?;
mouse.destroy?;
// Keyboard
let mut keyboard = new;
keyboard.create?;
keyboard.type_text?;
keyboard.tap?;
keyboard.press_combo?;
keyboard.destroy?;
API Reference
AgentHID Actions
Mouse
| Action | Parameters | Description |
|---|---|---|
mouse_move |
x: i32, y: i32 |
Move by relative offset |
mouse_click |
button?: string |
Click (left/right/middle) |
mouse_double_click |
button?: string |
Double click |
mouse_down |
button?: string |
Press button |
mouse_up |
button?: string |
Release button |
mouse_scroll |
delta: i8 |
Scroll wheel (+up/-down) |
Keyboard
| Action | Parameters | Description |
|---|---|---|
type |
text: string |
Type a string |
key_press |
key: string |
Press and release key |
key_down |
key: string |
Press key |
key_up |
key: string |
Release key |
key_combo |
modifiers: [string], key: string |
Key combination |
Modifiers: ctrl, shift, alt, cmd/meta/win
Keys: a-z, 0-9, enter, escape, backspace, tab, space, up, down, left, right, home, end, pageup, pagedown, delete, insert, f1-f12
Gamepad
| Action | Parameters | Description |
|---|---|---|
gamepad_press |
button: string |
Press button |
gamepad_release |
button: string |
Release button |
gamepad_left_stick |
x: u8, y: u8 |
Left stick (0-255, 128=center) |
gamepad_right_stick |
x: u8, y: u8 |
Right stick |
gamepad_triggers |
left: u8, right: u8 |
Triggers (0-255) |
Buttons: a, b, x, y, lb, rb, back, start, guide, left_stick, right_stick, dpad_up, dpad_down, dpad_left, dpad_right
Mouse API
Keyboard API
Gamepad API
Examples
# Basic mouse control
# Keyboard typing
# Agent browsing demo
# Auto-fill login form
# Copy & paste
# Browser shortcuts
# Window management
# Screenshot
# Drag and drop
# Mouse drawing
Permissions
macOS
Requires Accessibility permissions:
- System Preferences → Security & Privacy → Privacy → Accessibility
- Add your terminal or application
Linux
Requires access to /dev/uhid:
# Or add user to input group
Windows
No special permissions required for mouse/keyboard (uses SendInput API).
License
MIT License - see LICENSE