4 releases

0.1.3 Sep 14, 2020
0.1.2 Aug 2, 2019
0.1.1 Jul 16, 2019
0.1.0 Jul 16, 2019

#2 in #key-code

Download history 31/week @ 2024-06-10 29/week @ 2024-06-17 31/week @ 2024-06-24 2/week @ 2024-07-01 37/week @ 2024-07-08 25/week @ 2024-07-15 24/week @ 2024-07-22 34/week @ 2024-07-29 30/week @ 2024-08-05 24/week @ 2024-08-12 24/week @ 2024-08-19 23/week @ 2024-08-26 30/week @ 2024-09-02 32/week @ 2024-09-09 26/week @ 2024-09-16 50/week @ 2024-09-23

141 downloads per month
Used in nu_plugin_binaryview

MIT license

9KB
152 lines

Early release of a project to support raw key input in terminals. Currently, this supports the following raw keys across the major OSes:

  • LShift - Left Shift (or either Shift on some OSes)
  • LControl - Left Control
  • Back - Backspace
  • Space
  • Tab
  • Escape
  • LeftArrow
  • UpArrow
  • RightArrow
  • DownArrow
  • PageUp
  • PageDown
  • Alt

Rather than using events, rawkey offers a way to scan to see if the key is pressed or not.

use rawkey::{KeyCode, RawKey};

let mut rawkey = RawKey::new();

loop {
    if rawkey.is_pressed(KeyCode::Escape) {
        break;
    }
    if rawkey.is_pressed(KeyCode::UpArrow) {
        print!("Up ");
    }
    if rawkey.is_pressed(KeyCode::DownArrow) {
        print!("Down ");
    }
    if rawkey.is_pressed(KeyCode::LeftArrow) {
        print!("Left ");
    }
    if rawkey.is_pressed(KeyCode::RightArrow) {
        print!("Right ");
    }
    println!("");
}

Dependencies

~0–295KB