| Crates.io | input_query |
| lib.rs | input_query |
| version | 0.3.0 |
| created_at | 2025-09-14 17:38:36.121731+00 |
| updated_at | 2025-12-05 22:48:36.788833+00 |
| description | A library for querying key states without a window. |
| homepage | |
| repository | https://github.com/Murat65536/input-query |
| max_upload_size | |
| id | 1839002 |
| size | 37,713 |
A cross-platform Rust library for querying keyboard key states without requiring a window context.
| Platform | API Used | Background Thread | Notes |
|---|---|---|---|
| Linux | evdev |
Yes (5ms poll rate) | Requires read access to /dev/input/event* devices |
| Windows | GetAsyncKeyState (Win32) |
No (on-demand) | No special permissions required |
| macOS | CGEventSourceKeyState (Core Graphics) |
No (on-demand) | Requires "Input Monitoring" permission |
Add this to your Cargo.toml:
[dependencies]
input_query = "0.1.0"
use input_query::{InputHandler, KeyCode};
use std::thread;
use std::time::Duration;
fn main() {
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!");
}
// Your application logic here
thread::sleep(Duration::from_millis(10));
}
}
Note: On Linux, input events are monitored in a background thread automatically. On Windows and macOS, the state is queried on-demand. You no longer need to call update_inputs() - the library handles updates automatically!
You can run the included example with:
cargo run --example simple
This will demonstrate real-time key detection. Press ESC to exit the example.
On Linux, you need read access to input devices. You can either:
Add your user to the input group:
sudo usermod -a -G input $USER
Then log out and log back in.
Or run your application with appropriate permissions (not recommended for production).
On macOS, the application needs "Input Monitoring" permission:
No special setup required on Windows.
The library currently supports:
See the KeyCode enum for the complete list.
For detailed API documentation, run:
cargo doc --open
Or visit docs.rs (once published).
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.