Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about "Shift", "Alt" and "Ctrl" #43

Open
BlockyDeer opened this issue Feb 11, 2024 · 5 comments
Open

What about "Shift", "Alt" and "Ctrl" #43

BlockyDeer opened this issue Feb 11, 2024 · 5 comments

Comments

@BlockyDeer
Copy link

I can't find anything about how to get the state of "Shift", "Alt" and "Ctrl" in this crate. Are they missing?

@lemunozm
Copy link
Owner

Hi @BlockyDeer, yes they're missing.

Those keys do not generate any event in the terminal.

For some keys, you can try to infer them, i.e., you obtained 'A' instead of 'a', but that could also be due because Caps lock is enabled.

@BlockyDeer
Copy link
Author

Can I use the event of Crossterm to get events for those keys?

@lemunozm
Copy link
Owner

I think crossterm does not generate this kind of event. At least not for "standard" terminals. The x11 lib can generate that, but it's difficult to sync with the terminal key because they are totally different processes.

I am not sure if there exists an easy solution for this...

@TheYahton
Copy link

TheYahton commented Apr 22, 2024

idk about ruscii, but in my engine I use smth like this to handle Ctrl+C:

use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyEventState, KeyModifiers};

fn events() {
    if is_event_available().unwrap() {
        Event::Key(KeyEvent {
            code: KeyCode::Char('c'),
            modifiers: KeyModifiers::CONTROL,
            state: KeyEventState::NONE,
            kind: KeyEventKind::Press,
        }) => stop_program(),
    }
}

@alefnull
Copy link

alefnull commented Jun 8, 2024

hey, just popping in from another issue in this repo also related to input handling. as i mentioned over there, i was recently using ruscii in my first released app, and was having similar issues. i've since rewritten my app to use crossterm directly instead of relying on ruscii, since my little CLI toy is pretty dead simple to begin with and didn't really need the extra ruscii bits anyway.

in any case, just wanted to double up on the suggestion from @TheYahton above, as i just implemented this in my upcoming update and it works like a charm. i'm using 'Q', and <Ctrl+C> all as possible inputs to exit the program, and they all work flawlessly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants