How to get the console in raw mode in rust 🖤
Stacy Roll
Posted on October 25, 2023
Rust by default does not have a console management in pure raw mode. If you are looking for a way to handle keyboard events you can add the lightweight k_board library. Here is an example and the structure offered in the official documentation.
cargo add k_board
use k_board::{Keyboard, Keys};
fn main() {
for key in Keyboard::new() {
match key {
Keys::Up => //code 1
Keys::Down => //code 2
Keys::Enter => break,
_ => {}
}
}
}
pub enum Keys {
Up,
Down,
Left,
Right,
Enter,
Space,
Delete,
Escape,
Plus,
Minus,
Equal,
Power, ^
Slash, /
Backslash, \
Asterisk, *
Point,
Comma,
Hashtag,
Pipe, |
Percent, %
Ampersand,
Currency, $
TwoPoints, :
Semicolon, ;
OpenSquareBracket, [
CloseSquareBracket, ]
OpenCurlyBrace, {
CloseCurlyBrace, }
OpenQuestionMark, ¿
CloseQuestionMark, ?
OpenParenthesis, (
CloseParenthesis, )
LessThan, <
GreaterThan, >
Apostrophe, '
At, @
Home,
End,
Tab,
Backtab,
Insert,
Letter(char),
Number(u8),
F(u8),
Ctrl(char),
Alt(char),
Null,
}
💖 💪 🙅 🚩
Stacy Roll
Posted on October 25, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.