pub struct Keystroke {
pub modifiers: Modifiers,
pub key: String,
pub key_char: Option<String>,
}Expand description
A keystroke and associated metadata generated by the platform
Fields§
§modifiers: Modifiersthe state of the modifier keys at the time the keystroke was generated
key: Stringkey is the character printed on the key that was pressed e.g. for option-s, key is “s” On layouts that do not have ascii keys (e.g. Thai) this will be the ASCII-equivalent character (q instead of ๆ), and the typed character will be present in key_char.
key_char: Option<String>key_char is the character that could have been typed when this binding was pressed. e.g. for s this is “s”, for option-s “ß”, and cmd-s None
Implementations§
Source§impl Keystroke
impl Keystroke
Sourcepub fn should_match(&self, target: &KeybindingKeystroke) -> bool
pub fn should_match(&self, target: &KeybindingKeystroke) -> bool
When matching a key we cannot know whether the user intended to type
the key_char or the key itself. On some non-US keyboards keys we use in our
bindings are behind option (for example $ is typed alt-ç on a Czech keyboard),
and on some keyboards the IME handler converts a sequence of keys into a
specific character (for example " is typed as " space on a brazilian keyboard).
This method assumes that self was typed and `target’ is in the keymap, and checks
both possibilities for self against the target.
Sourcepub fn parse(source: &str) -> Result<Self, InvalidKeystrokeError>
pub fn parse(source: &str) -> Result<Self, InvalidKeystrokeError>
key syntax is: [secondary-][ctrl-][alt-][shift-][cmd-][fn-]key[->key_char] key_char syntax is only used for generating test events, secondary means “cmd” on macOS and “ctrl” on other platforms when matching a key with an key_char set will be matched without it.
Sourcepub fn unparse(&self) -> String
pub fn unparse(&self) -> String
Produces a representation of this key that Parse can understand.
Sourcepub fn is_ime_in_progress(&self) -> bool
pub fn is_ime_in_progress(&self) -> bool
Returns true if this keystroke left the ime system in an incomplete state.
Sourcepub fn with_simulated_ime(self) -> Self
pub fn with_simulated_ime(self) -> Self
Returns a new keystroke with the key_char filled. This is used for dispatch_keystroke where we want users to be able to simulate typing “space”, etc.
Source§impl Keystroke
impl Keystroke
Sourcepub fn underlying_dead_key(keysym: Keysym) -> Option<String>
pub fn underlying_dead_key(keysym: Keysym) -> Option<String>
Returns which symbol the dead key represents https://developer.mozilla.org/en-US/docs/Web/API/UI_Events/Keyboard_event_key_values#dead_keycodes_for_linux
Trait Implementations§
Source§impl AsKeystroke for Keystroke
impl AsKeystroke for Keystroke
Source§fn as_keystroke(&self) -> &Keystroke
fn as_keystroke(&self) -> &Keystroke
Source§impl<'de> Deserialize<'de> for Keystroke
impl<'de> Deserialize<'de> for Keystroke
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Keystroke
impl StructuralPartialEq for Keystroke
Auto Trait Implementations§
impl Freeze for Keystroke
impl RefUnwindSafe for Keystroke
impl Send for Keystroke
impl Sync for Keystroke
impl Unpin for Keystroke
impl UnwindSafe for Keystroke
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
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.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§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().