Crates.io | keyboard_listener_windows |
lib.rs | keyboard_listener_windows |
version | 0.2.0 |
source | src |
created_at | 2024-02-27 12:24:10.568335 |
updated_at | 2024-03-11 09:42:55.45126 |
description | You can use this library to listen your keyboard press and release ON windows. |
homepage | https://github.com/LemonNekoGH/keyboard_listener_windows |
repository | https://github.com/LemonNekoGH/keyboard_listener_windows |
max_upload_size | |
id | 1155043 |
size | 11,995 |
Simple library to listen globally to keyboard ONLY on Windows.
This library is subset of caret rdev.
You should use crate rdev if you don't just need to listen on Windows.
$ cargo add keyboard_listener_windows
Example:
use std::time::Duration;
use keyboard_listener_windows::{start_listen, stop_listen, Event};
fn main() {
start_listen(callback);
println!("start listen");
// you can stop listen any time
std::thread::spawn(||{
std::thread::sleep(Duration::new(5,0));
stop_listen();
println!("stop listen")
}).join().unwrap();
}
fn callback(event: Event) {
println!("Keyboard event: {:?}", event);
}
Sample output:
start listen
Keyboard event: Event { timestamp: 1709032907009, is_key_down: true, key: "KeyA" }
Keyboard event: Event { timestamp: 1709032907036, is_key_down: true, key: "KeyS" }
Keyboard event: Event { timestamp: 1709032907140, is_key_down: true, key: "KeyD" }
Keyboard event: Event { timestamp: 1709032907216, is_key_down: false, key: "KeyA" }
Keyboard event: Event { timestamp: 1709032907373, is_key_down: false, key: "KeyS" }
Keyboard event: Event { timestamp: 1709032907456, is_key_down: false, key: "KeyD" }
stop listen
You can clone this repository then run this example using cargo:
$ cd example/listen && cargo run
OK, that's all, if you need more feature, please use crate rdev.