bracket-lib icon indicating copy to clipboard operation
bracket-lib copied to clipboard

Ctrl + <key> combination is only detected if <key> is kept pressed first and then ctrl instead of the other way around.

Open micutio opened this issue 5 years ago • 3 comments

This happens running the tutorial 74 under Ubuntu 20.10. Expected behaviour would be to keep pressing ctrl first and then the key, but then the bracket-lib only detects instead of ctrl+ in that case. The same happens with shift.

micutio avatar Dec 10 '20 15:12 micutio

A workaround is to turn on the "advanced input API" (call with_advanced_input(true) on the BTermBuilder) and add the following code to the game-loop:

    let mut input = INPUT.lock();

    ctx.shift = input.key_pressed_set().contains(&VirtualKeyCode::LShift)
                || input.key_pressed_set().contains(&VirtualKeyCode::RShift);

    #[allow(clippy::single_match)]
    input.for_each_message(|event| match event {
        BEvent::CloseRequested => ctx.quitting = true,
        _ => (),
    });

Do the equivalent for ctx.ctrl. This isn't 100% correct though, but works ok for me (once in a while the release of the shift-key goes missing for some reason, I've not yet debugged why as I intend to switch all the input handling to the advanced input API).

bofh69 avatar Jan 03 '21 11:01 bofh69

A workaround is to turn on the "advanced input API" (call with_advanced_input(true) on the BTermBuilder) and add the following code to the game-loop:

    let mut input = INPUT.lock();

    ctx.shift = input.key_pressed_set().contains(&VirtualKeyCode::LShift)
                || input.key_pressed_set().contains(&VirtualKeyCode::RShift);

    #[allow(clippy::single_match)]
    input.for_each_message(|event| match event {
        BEvent::CloseRequested => ctx.quitting = true,
        _ => (),
    });

Do the equivalent for ctx.ctrl. This isn't 100% correct though, but works ok for me (once in a while the release of the shift-key goes missing for some reason, I've not yet debugged why as I intend to switch all the input handling to the advanced input API).

Thanks for your help! This works well for shift and control. I haven't yet reproduced the missing shift release, but will keep an eye on it, so thank you for bringing that up.

micutio avatar Jan 04 '21 15:01 micutio

Labeling this as an enhancement because the library really needs modifier key handling revisited. Advanced input is the way to go for a lot of this if you want really slick results (I tried to keep the normal mode simple), but hopefully I can find some middle ground. I'll try to get to this after 0.8.2 ships.

thebracket avatar Feb 11 '21 17:02 thebracket