raw-input
raw-input is a lightweight, high-performance cross-platform Rust library designed to capture and simulate global input events (keyboard and mouse). It is ideal for building global hotkey managers, input monitors, automation scripts, and accessibility tools.
✨ Features
- Global Event Listening: Capture system-wide keyboard, mouse movement, clicks, and scroll events without requiring window focus.
- Subscription Management: Each listener returns a
SubscriptionHandlethat allows you to Pause, Resume, or Unsubscribe at runtime. - Input Interception (Grab): Intercept and optionally block specific input events from reaching other applications.
- Input Simulation: Inject physical-level keyboard and mouse events, supporting both relative movement and absolute screen coordinates.
- Display Utilities: Query monitor information, physical resolutions, and DPI scale factors.
- Thread-Safe: Designed with
DashMapand atomic operations for safe multi-threaded usage.
🚀 Quick Start
Install this to your Cargo.toml:
Basic Example: Monitoring Global Input
use thread;
use Duration;
use ;
🛠 Core Modules
| Module | Description |
|---|---|
Core |
The underlying driver. Manages low-level hooks and the OS event loop. |
Listen |
The primary interface for subscribing to global input events. |
Simulate |
Provides tools to programmatically synthesize keyboard and mouse input. |
Grab |
Allows exclusive access to inputs by blocking them for other applications. |
Display |
Utilities for monitor enumeration and coordinate mapping. |
📦 Optional Features
serialize: Enablesserdesupport (Serialize/Deserialize) for event structures likeEvent,Key, andPoint.
🖥 Platform Support
| OS | Status | Notes |
|---|---|---|
| Windows | ✅ Supported | Implemented via SetWindowsHookEx and Raw Input API. |
| macOS | 🚧 Planned | Will be based on CGEventTap. |
| Linux | 🚧 Planned | Will be based on XRecord or evdev. |