Issue with corssterm KeyEvent

I am having the following code. When down arrow key is pressed the " println!("down pressed:\r"); " is called twice. anything I am missing out?

loop {
if let Event::Key(event) = event::read().expect("Failed to read line") {
match event {
KeyEvent {
code: KeyCode::Char('q'),
modifiers: event::KeyModifiers::NONE, ..
} => break,
KeyEvent {
code: KeyCode::Down,
modifiers: event::KeyModifiers::NONE, ..
} => {
println!("down pressed:\r");
},
_ => {
//todo
}
}
//println!("{:?}\r", event);
};
}

you ignored the kind field in the pattern, my guess is you received two event, one is KeyEventKind::Press, another is KeyEventKind::Release

1 Like

thank you very much @nerditation ... after setting kind field to Press... it worked... i changed it to ...

KeyEvent {
code: KeyCode::Down,
modifiers: event::KeyModifiers::NONE,
kind: event::KeyEventKind::Press,..
} =>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.