How to get the Ctrl + C event in rust? 🔭🔮
Stacy Roll

Stacy Roll @stacy-roll

About: I love rust code & tech books 🦀

Location:
USA
Joined:
Oct 15, 2023

How to get the Ctrl + C event in rust? 🔭🔮

Publish Date: Jan 23 '24
3 0

If you are on a linux distro and you want to obtain the Ctrl + C event before the process ends in your terminal, in this article I am going to show you how to do it!

Cargo.toml

[dependencies]
k_board = { version = "1.2.4", features = ["ctrl_lower_letter"] }
Enter fullscreen mode Exit fullscreen mode

main.rs

use k_board::{keyboard::Keyboard, keys::Keys};

fn main() {
    for key in Keyboard::new() {
        match key {
            Keys::Ctrl('c') => {
                println!("Yeah, you press Ctrl + C and the console doest ends!!");
                break;
            },
            _ => (),
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

See you in the next article❣️🤗!!

Comments 0 total

    Add comment