Skip to main content

KeyEvent

Struct KeyEvent 

Source
pub struct KeyEvent { /* private fields */ }
Expand description

A keyboard input event.

Holds the key, whether it went down or up, the modifier keys held with it and the text it typed.

Implementations§

Source§

impl KeyEvent

Source

pub fn new( key: Key, text: impl Into<String>, modifiers: Modifiers, type_: KeyEventType, ) -> KeyEvent

Creates a key event. text is what the key typed with the keyboard layout and modifiers applied (Shift+A types “A”), empty for keys that type nothing.

Source

pub fn key_down(key: Key, text: impl Into<String>) -> KeyEvent

Creates a key down event with the given key and text.

Source

pub fn key_up(key: Key) -> KeyEvent

Creates a key up event for key.

Source

pub fn key_down_with_modifiers( key: Key, text: impl Into<String>, modifiers: Modifiers, ) -> KeyEvent

Creates a key down event with modifiers.

Source

pub fn with_repeat_count(self, repeat_count: u32) -> KeyEvent

This event as the repeat_countth repeat of a held key.

Source

pub fn key(&self) -> Key

The key that went down or up.

Source

pub fn type_(&self) -> KeyEventType

Whether the key went down or up.

Source

pub fn text(&self) -> &str

The text this key typed, empty for keys that type nothing.

Source

pub fn modifiers(&self) -> Modifiers

The modifier keys held with this key.

Source

pub fn is_shift_pressed(&self) -> bool

Whether a Shift key was held.

Source

pub fn is_ctrl_pressed(&self) -> bool

Whether a Control key was held.

Source

pub fn is_alt_pressed(&self) -> bool

Whether an Alt key was held.

Source

pub fn is_meta_pressed(&self) -> bool

Whether a Meta key was held.

Source

pub fn utf16_code_point(&self) -> Option<u32>

The Unicode code point of the character this key typed, if it typed one.

Source

pub fn native_key_event(&self) -> NativeKeyEvent

What the platform reported beyond the key, such as the repeat count.

Source

pub fn is_key_down(&self) -> bool

Returns true if this is a key down event.

Source

pub fn has_text(&self) -> bool

Returns true if this key produces printable text.

Trait Implementations§

Source§

impl Clone for KeyEvent

Source§

fn clone(&self) -> KeyEvent

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for KeyEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Display for KeyEvent

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Eq for KeyEvent

Source§

impl PartialEq for KeyEvent

Source§

fn eq(&self, other: &KeyEvent) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for KeyEvent

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> LayoutData for T
where T: Any + Debug + PartialEq,

Source§

fn same_as(&self, other: &(dyn LayoutData + 'static)) -> bool

Whether other holds the same data, so a parent can keep its last measure.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

The data as Any, to read it by its type.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.