keyboard_listener_windows

Crates.iokeyboard_listener_windows
lib.rskeyboard_listener_windows
version0.2.0
sourcesrc
created_at2024-02-27 12:24:10.568335
updated_at2024-03-11 09:42:55.45126
descriptionYou can use this library to listen your keyboard press and release ON windows.
homepagehttps://github.com/LemonNekoGH/keyboard_listener_windows
repositoryhttps://github.com/LemonNekoGH/keyboard_listener_windows
max_upload_size
id1155043
size11,995
LemonNeko (LemonNekoGH)

documentation

README

keyboard_listener_windows

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.

Install

$ cargo add keyboard_listener_windows

Listening to global events

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.

Commit count: 0

cargo fmt