#unix #key #windows #getch

getch-rs

getch for Windows and Unix

6 releases

0.2.0 Feb 3, 2024
0.1.4 Aug 25, 2023
0.1.3 Apr 27, 2023
0.1.0 Feb 1, 2023

#293 in Hardware support

Download history 10/week @ 2024-01-26 12/week @ 2024-02-02 23/week @ 2024-02-09 31/week @ 2024-02-16 51/week @ 2024-02-23 33/week @ 2024-03-01 66/week @ 2024-03-08 44/week @ 2024-03-15 31/week @ 2024-03-22 69/week @ 2024-03-29 48/week @ 2024-04-05 50/week @ 2024-04-12 53/week @ 2024-04-19 43/week @ 2024-04-26 38/week @ 2024-05-03 26/week @ 2024-05-10

168 downloads per month
Used in sisterm

MIT license

15KB
279 lines

getch-rs

Actions Status Crates.io Documentation License

getch for Windows and Unix.

Usage

Cargo.toml

[dependencies]
getch-rs = "0.2"

main.rs

use getch_rs::Getch;

fn main() {
    let g = Getch::new();

    if let Ok(key) = g.getch() {
        println!("{:?}", key);
    }
}

Examples

$ cargo run --example getch

Contributing

This project welcomes your PR and issues. For example, fixing bugs, adding features, refactoring, etc.


lib.rs:

getch-rs

getch is a C language function designed to capture a single character input from the keyboard without requiring the user to press the Enter key. This function suspends program execution until the user provides input. Typically employed in console-based programs, it proves useful for scenarios where menu selection or awaiting key input is required.

Example

use getch_rs::{Getch, Key};

fn main() {
    let g = Getch::new();

    println!("press `q` to exit");

    loop {
        match g.getch() {
            Ok(Key::Char('q')) => break,
            Ok(key) => println!("{:?}", key),
            Err(e) => println!("{}", e),
        }
    }
}

Dependencies

~1.5MB
~35K SLoC