Keyboard Identifier
A cross-platform Rust library for uniquely identifying physical keyboards, tracking their hardware ports, and listening to device-specific events (key presses, releases, plug, and unplug events).
Built with tokio, this library abstracts away OS-specific input APIs to provide a unified, asynchronous event-driven interface. Perfect for projects involving custom macro pads, POS systems, or multi-keyboard setups.
Features
- Device Differentiation: Identify keyboards by Vendor ID, Product ID, Serial Number, and Name.
- Topology Tracking: Differentiate identical keyboards plugged into different USB ports using
PortID(physical path). - Async Event Callbacks: Listen to
KeyAction(press/release),Plugged, andUnpluggedevents non-blocking via Tokio. - Rich Key Events: Integrates the external W3C standard using the
keyboard-typescrate to provide detailed key event data (logical key, physical code, modifiers, and repeat state)[cite: 1, 3]. - Cross-Platform: Native support for Windows, Linux, and macOS.
Installation
Add this to your Cargo.toml:
[]
= "0.1.0" # replace with your actual version
= { = "1.53.1", = ["macros", "rt", "sync", "rt-multi-thread"] }
Example Usage
This example demonstrates how to list available keyboards, ask the user to press a key to "select" a specific keyboard, and then monitor events specifically for that device.
use ;
async
Core Types
Keyboard
The primary struct representing a connected device. It contains two identifiers:
keyboard_id: Identifying information about the hardware model (Name, Vendor ID, Product ID, Serial).port_id: Identifying information about the physical connection (e.g., USB port topology).
Note: Two identical keyboards from the same manufacturer will have identical KeyboardIDs, but different PortIDs.
KeyEvent
A rename to KeyboardEvent struct from keyboard_types crate, found on : https://crates.io/crates/keyboard-types
although key field is not set
Supported OS
- Windows (
target_os = "windows"): Uses Raw Input and SetupAPI. - Linux (
target_os = "linux"): Uses standard input file descriptors. - macOS (
target_os = "macos"): Native implementation using FFI and C callbacks[cite: 2].
License
This project is licensed under [MIT].