#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

#928 in Hardware support

Download history 34/week @ 2024-10-29 34/week @ 2024-11-05 33/week @ 2024-11-12 86/week @ 2024-11-19 41/week @ 2024-11-26 49/week @ 2024-12-03 191/week @ 2024-12-10 75/week @ 2024-12-17 30/week @ 2024-12-24 67/week @ 2024-12-31 73/week @ 2025-01-07 120/week @ 2025-01-14 90/week @ 2025-01-21 93/week @ 2025-01-28 151/week @ 2025-02-04 150/week @ 2025-02-11

499 downloads per month
Used in 2 crates

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

~2MB
~36K SLoC