Crates.io | xekeys |
lib.rs | xekeys |
version | 2.0.0 |
source | src |
created_at | 2021-05-31 00:16:01.235588 |
updated_at | 2021-06-27 19:09:26.687505 |
description | A simple crate for getting key-presses. |
homepage | https://codeberg.org/RustedTerrier/xekeys |
repository | https://codeberg.org/RustedTerrier/xekeys |
max_upload_size | |
id | 404038 |
size | 17,270 |
A simple program to gather key-presses.
None of the mod keys are case sensitive.
Ctrl does not work on '-', ';', ''', ',', '.', '[' or '+'.
Super only supports arrow keys as I found no way to support regular keys. Any pull requests on this issue would be appreciated.
Raw mode is needed for most of the key detection.
extern crate xekeys;
use xekeys::{get_keys, Keys};
fn main() {
loop {
// Here we get the keypresses as a struct.
let keys = get_keys();
// Here we check if q is pressed and control is pressed and if so, we break.
match keys {
| Keys::CtrlChar('q') => break,
| _ => {}
};
}
}
When I was using termion, I came to the realization that I was unabled to detect ctrl+arrow keys, something I needed. So I made my own crate; but, to justify using this over termion, I added most of the functionality of termion key presses and some extra, such as more modifiers with arrow keys and function keys up to 20.
XEKEYS uses BSD-3 clause.
I dont want to make a full termion alternative, termion is already great; but, if you want one, I suggest using this for keypresses, raw_tty for raw mode, lliw for styling, and I guess you can do the cursor movement using ANSI escape codes as well as clearing.