Expand description
§input_query
A cross-platform Rust library for querying keyboard key states without requiring a window context.
This library provides a simple, unified API for checking if keyboard keys are currently pressed across Linux, Windows, and macOS platforms.
§Platform Support
- Linux: Uses
evdevto directly read input events from device files. Events are monitored in a background thread that polls every 5ms. - Windows: Uses
GetAsyncKeyStatefrom the Win32 API. State is queried on-demand. - macOS: Uses
CGEventSourceKeyStatefrom the Core Graphics framework. State is queried on-demand.
§Usage
use input_query::{InputHandler, KeyCode};
use std::thread;
use std::time::Duration;
let handler = InputHandler::new();
loop {
if handler.is_pressed(KeyCode::KeyEsc) {
println!("Escape key is pressed!");
break;
}
if handler.is_pressed(KeyCode::KeySpace) {
println!("Space bar is pressed!");
}
thread::sleep(Duration::from_millis(10));
}§Note on Permissions
- Linux: Requires read access to
/dev/input/event*devices. You may need to add your user to theinputgroup or run with appropriate permissions. - macOS: Requires accessibility permissions. The application may need to be granted “Input Monitoring” permission in System Preferences → Security & Privacy → Privacy.
- Windows: No special permissions required.
Re-exports§
pub use input_handler::InputHandler;pub use input_handler::KeyCode;
Modules§
- input_
handler - Platform-specific input handler implementations and key code definitions.