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

Key press event fires twice #797

Open
dev-ardi opened this issue Jul 26, 2023 · 3 comments
Open

Key press event fires twice #797

dev-ardi opened this issue Jul 26, 2023 · 3 comments

Comments

@dev-ardi
Copy link

Describe the bug
Event fires on keyup and keydown

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://github.com/fdehau/tui-rs/blob/master/examples/list.rs
  2. Compile
  3. Press down
  4. Jumps twice down

Expected behavior
It only fires once

OS
Windows

Terminal/Console
conhost, alacritty, powershell.

@Piturnah
Copy link
Contributor

Since 0.26 Crossterm detects key release events for Windows which means that downstream has to explicitly ignore it if you only want one event to fire.

For example, this change to the lines in list.rs from line 188 should do it:

if let Event::Key(KeyEvent {
    code,
    kind: KeyEventKind::Press,
    ..
}) = event::read()?
{
    match code {
        KeyCode::Char('q') => return Ok(()),
        KeyCode::Left => app.items.unselect(),
        KeyCode::Down => app.items.next(),
        KeyCode::Up => app.items.previous(),
        _ => {}
    }
}

programingjd added a commit to programingjd/heh that referenced this issue Jul 30, 2023
…sequence, key events were handled twice, one for key press and one for key release.

This fixes the issue by ignoring events when the type is not a key press.
See relevant issue on crossterm:
crossterm-rs/crossterm#797
ndd7xv pushed a commit to ndd7xv/heh that referenced this issue Jul 30, 2023
…sequence, key events were handled twice, one for key press and one for key release. (#78)

This fixes the issue by ignoring events when the type is not a key press.
See relevant issue on crossterm:
crossterm-rs/crossterm#797
@lthoerner
Copy link

Should this be closed?

@Piturnah
Copy link
Contributor

Possibly waiting for #778?

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

3 participants