pub enum KeyEvent {
Down(KeyDownEvent),
Up(KeyUpEvent),
Repeat(KeyRepeatEvent),
}Expand description
Defines the interface for keyboard key events.
The KeyEvent provides a universal model for key event information from a
hardware keyboard across platforms.
See also:
HardwareKeyboardfor full introduction to key event model and handling.KeyDownEvent, the variant for events representing the user pressing a key.KeyRepeatEvent, the variant for events representing the user holding a key, causing repeated events.KeyUpEvent, the variant for events representing the user releasing a key.
Variants§
Implementations§
Source§impl KeyEvent
impl KeyEvent
Sourcepub fn physical_key(&self) -> PhysicalKeyboardKey
pub fn physical_key(&self) -> PhysicalKeyboardKey
Returns an object representing the physical location of this key.
A PhysicalKeyboardKey represents a USB HID code sent from the keyboard,
ignoring the key map, modifier keys (like SHIFT), and the label on the key.
PhysicalKeyboardKeys are used to describe and test for keys in a
particular location. A PhysicalKeyboardKey may have a name, but the name
is a mnemonic (“keyA” is easier to remember than 0x70004), derived from the
key’s effect on a QWERTY keyboard. The name does not represent the key’s
effect whatsoever (a physical “keyA” can be the Q key on an AZERTY
keyboard).
For instance, if you wanted to make a game where the key to the right of
the CAPS LOCK key made the player move left, you would be comparing a
physical key with PhysicalKeyboardKey::KEY_A, since that is the key next
to the CAPS LOCK key on a QWERTY keyboard. This would return the same thing
even on an AZERTY keyboard where the key next to the CAPS LOCK produces a
“Q” when pressed.
If you want to make your app respond to a key with a particular character
on it regardless of location of the key, use
logical_key instead.
Also, even though physical keys are defined with USB HID codes, their values are not necessarily the same HID codes produced by the hardware and presented to the driver. On most platforms, Flutter has to map the platform representation back to a HID code because the original HID code is not provided.
Sourcepub fn logical_key(&self) -> LogicalKeyboardKey
pub fn logical_key(&self) -> LogicalKeyboardKey
Returns an object representing the logical key that was pressed.
This method takes into account the key map and modifier keys (like SHIFT) to determine which logical key to return.
If you are looking for the character produced by a key event, use
character instead.
Sourcepub fn character(&self) -> Option<&str>
pub fn character(&self) -> Option<&str>
Returns the Unicode character (grapheme cluster) completed by this keystroke, if any.
This will only return a character if this keystroke, combined with any
preceding keystroke(s), generates a character, and only on a “key down”
event. It will return None if no character has been generated by the
keystroke (e.g. a “dead” or “combining” key), or if the corresponding key
is a key without a visual representation, such as a modifier key or a
control key. It will also return None if this is a “key up” event.
This can return multiple Unicode code points, since some characters (more accurately referred to as grapheme clusters) are made up of more than one code point.
The character doesn’t take into account edits by an input method editor (IME), or manage the visibility of the soft keyboard on touch devices.
The character is not available on KeyUpEvents.
Sourcepub fn time_stamp(&self) -> Duration
pub fn time_stamp(&self) -> Duration
Time of event, relative to an arbitrary start point.
All events share the same time stamp origin.
Sourcepub fn device_type(&self) -> KeyEventDeviceType
pub fn device_type(&self) -> KeyEventDeviceType
The source device type for the key event.
Not all platforms supply an accurate type.
Defaults to KeyEventDeviceType::Keyboard.
Sourcepub fn synthesized(&self) -> bool
pub fn synthesized(&self) -> bool
Whether this event is synthesized by Flutter to synchronize key states.
A non-synthesized event is converted from a native event, and a native event can only be converted to one non-synthesized event. Some properties might be changed during the conversion (for example, a native repeat event might be converted to a Flutter down event when necessary.)
A synthesized event is created without a source native event in order to synchronize key states. For example, if the native platform shows that a shift key that was previously held has been released somehow without the key up event dispatched (probably due to loss of focus), a synthesized key up event will be added to regularized the event stream.
For detailed introduction to the regularized event model, see
HardwareKeyboard.
A KeyRepeatEvent is never synthesized.
Sourcepub fn to_key_data(&self) -> KeyData
pub fn to_key_data(&self) -> KeyData
The host’s KeyData this event was made from, as KeyEventManager reads it: what an
app hands back to the host, such as a key it kept back for the menu bar
(MenuBar::perform_key_equivalent).
Trait Implementations§
impl Eq for KeyEvent
Source§impl From<KeyDownEvent> for KeyEvent
impl From<KeyDownEvent> for KeyEvent
Source§fn from(event: KeyDownEvent) -> KeyEvent
fn from(event: KeyDownEvent) -> KeyEvent
Source§impl From<KeyRepeatEvent> for KeyEvent
impl From<KeyRepeatEvent> for KeyEvent
Source§fn from(event: KeyRepeatEvent) -> KeyEvent
fn from(event: KeyRepeatEvent) -> KeyEvent
Source§impl From<KeyUpEvent> for KeyEvent
impl From<KeyUpEvent> for KeyEvent
Source§fn from(event: KeyUpEvent) -> KeyEvent
fn from(event: KeyUpEvent) -> 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 UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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
key and return true if they are equal.