pub struct KeyboardData {
    pub char_code: u32,
    pub key: String,
    pub key_code: KeyCode,
    pub alt_key: bool,
    pub ctrl_key: bool,
    pub meta_key: bool,
    pub shift_key: bool,
    pub locale: String,
    pub location: usize,
    pub repeat: bool,
    pub which: usize,
}

Fields

char_code: u32key: String

Identify which “key” was entered.

This is the best method to use for all languages. They key gets mapped to a String sequence which you can match on. The key isn’t an enum because there are just so many context-dependent keys.

A full list on which keys to use is available at: https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key/Key_Values

Example

match event.key().as_str() {
    "Esc" | "Escape" => {}
    "ArrowDown" => {}
    "ArrowLeft" => {}
     _ => {}
}
key_code: KeyCode

Get the key code as an enum Variant.

This is intended for things like arrow keys, escape keys, function keys, and other non-international keys. To match on unicode sequences, use the [KeyboardEvent::key] method - this will return a string identifier instead of a limited enum.

Example

use dioxus::KeyCode;
match event.key_code() {
    KeyCode::Escape => {}
    KeyCode::LeftArrow => {}
    KeyCode::RightArrow => {}
    _ => {}
}
alt_key: bool

Indicate if the alt modifier key was pressed during this keyboard event

ctrl_key: bool

Indicate if the ctrl modifier key was pressed during this keyboard event

meta_key: bool

Indicate if the meta modifier key was pressed during this keyboard event

shift_key: bool

Indicate if the shift modifier key was pressed during this keyboard event

locale: Stringlocation: usizerepeat: boolwhich: usize

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Should always be Self
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.