DEV Community

Stacy Roll
Stacy Roll

Posted on

2 1

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)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more