diff --git a/examples/event-match-modifiers.rs b/examples/event-match-modifiers.rs index c3f75e95..ac9daefd 100644 --- a/examples/event-match-modifiers.rs +++ b/examples/event-match-modifiers.rs @@ -4,43 +4,42 @@ use crossterm::event::{Event, KeyCode, KeyEvent, KeyModifiers}; -fn match_event(read_event: Event) { - match read_event { - // Match one one modifier: - Event::Key(KeyEvent { - modifiers: KeyModifiers::CONTROL, - code, - .. - }) => { - println!("Control + {:?}", code); - } - Event::Key(KeyEvent { - modifiers: KeyModifiers::SHIFT, - code, - .. - }) => { - println!("Shift + {:?}", code); - } - Event::Key(KeyEvent { - modifiers: KeyModifiers::ALT, - code, - .. - }) => { - println!("Alt + {:?}", code); - } +fn match_event(event: Event) { + if let Some(key) = event.as_key_press() { + match key { + KeyEvent { + modifiers: KeyModifiers::CONTROL, + code, + .. + } => { + println!("Control + {:?}", code); + } + KeyEvent { + modifiers: KeyModifiers::SHIFT, + code, + .. + } => { + println!("Shift + {:?}", code); + } + KeyEvent { + modifiers: KeyModifiers::ALT, + code, + .. + } => { + println!("Alt + {:?}", code); + } - // Match on multiple modifiers: - Event::Key(KeyEvent { - code, modifiers, .. - }) => { - if modifiers == (KeyModifiers::ALT | KeyModifiers::SHIFT) { - println!("Alt + Shift {:?}", code); - } else { - println!("({:?}) with key: {:?}", modifiers, code) + // Match on multiple modifiers: + KeyEvent { + code, modifiers, .. + } => { + if *modifiers == (KeyModifiers::ALT | KeyModifiers::SHIFT) { + println!("Alt + Shift {:?}", code); + } else { + println!("({:?}) with key: {:?}", modifiers, code) + } } } - - _ => {} } }