Skip to content

Commit

Permalink
Add a small example for working out control keys (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka authored Jan 9, 2024
1 parent 50ccfcd commit ed4ca61
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/keyboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
use std::io;

use console::{Key, Term};

fn main() -> io::Result<()> {
let term = Term::stdout();
term.write_line("Press any key. Esc to exit")?;
loop {
let key = term.read_key()?;
term.write_line(&format!("You pressed {:?}", key))?;
if key == Key::Escape {
break;
}
}
Ok(())
}

0 comments on commit ed4ca61

Please sign in to comment.