pub struct KeyEvent {
pub key_code: KeyCode,
pub text: String,
pub modifiers: Modifiers,
pub event_type: KeyEventType,
}Expand description
A keyboard input event.
Contains information about which key was pressed/released, the text it produces (if any), and modifier state.
Fields§
§key_code: KeyCodeThe physical key that was pressed.
text: StringThe text produced by this key press (may be empty for non-character keys). This accounts for keyboard layout and modifiers (e.g., Shift+A = “A”).
modifiers: ModifiersCurrent state of modifier keys.
event_type: KeyEventTypeType of event (down or up).
Implementations§
Source§impl KeyEvent
impl KeyEvent
Sourcepub fn new(
key_code: KeyCode,
text: impl Into<String>,
modifiers: Modifiers,
event_type: KeyEventType,
) -> KeyEvent
pub fn new( key_code: KeyCode, text: impl Into<String>, modifiers: Modifiers, event_type: KeyEventType, ) -> KeyEvent
Creates a new key event.
Sourcepub fn key_down(key_code: KeyCode, text: impl Into<String>) -> KeyEvent
pub fn key_down(key_code: KeyCode, text: impl Into<String>) -> KeyEvent
Creates a key down event with the given key code and text.
Sourcepub fn key_down_with_modifiers(
key_code: KeyCode,
text: impl Into<String>,
modifiers: Modifiers,
) -> KeyEvent
pub fn key_down_with_modifiers( key_code: KeyCode, text: impl Into<String>, modifiers: Modifiers, ) -> KeyEvent
Creates a key down event with modifiers.
Sourcepub fn is_key_down(&self) -> bool
pub fn is_key_down(&self) -> bool
Returns true if this is a key down event.
Trait Implementations§
impl Eq for KeyEvent
impl StructuralPartialEq for KeyEvent
Auto Trait Implementations§
impl Freeze for KeyEvent
impl RefUnwindSafe for KeyEvent
impl Send for KeyEvent
impl Sync for KeyEvent
impl Unpin for KeyEvent
impl UnwindSafe for KeyEvent
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.