Skip to content

sophiajt/rawkey

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!("");
}

About

Raw key input for terminals

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages