DEV Community

Stacy Roll
Stacy Roll

Posted on

How to get the Ctrl + C event in rust? ๐Ÿ”ญ๐Ÿ”ฎ

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โฃ๏ธ๐Ÿค—!!

Top comments (0)