Skip to main content

KeyStroke

Struct KeyStroke 

Source
pub struct KeyStroke {
    pub key: Key,
    pub modifiers: Modifiers,
}
Expand description

A single keyboard chord: a key plus its modifiers.

Fields§

§key: Key§modifiers: Modifiers

Implementations§

Source§

impl KeyStroke

Source

pub fn new(key: Key, modifiers: Modifiers) -> Self

Source

pub fn ctrl(key: Key) -> Self

A chord on Ctrl.

Read as a declared shortcut default this carries the cross-platform primary-accelerator convention: see with_command_convention for what the registry does with it on macOS. Use command when you want that intent stated outright, and new with Modifiers::CTRL plus ShortcutBuilder::literal_modifiers when you mean physical Control on every platform.

Source

pub fn ctrl_shift(key: Key) -> Self

Source

pub fn command(key: Key) -> Self

A chord on the platform’s primary accelerator: ⌘S on macOS, Ctrl+S on Windows and Linux. See Modifiers::COMMAND.

Equivalent to ctrl once a declared shortcut has been resolved, but it says so at the call site — which matters for the chords built outside the registry, like the copy/paste labels a context menu renders for itself.

Source

pub fn command_shift(key: Key) -> Self

A chord on the platform’s primary accelerator plus Shift: ⇧⌘Z on macOS, Ctrl+Shift+Z on Windows and Linux.

Source

pub fn alt(key: Key) -> Self

Source

pub fn with_command_convention(self) -> Self

This chord with a declared Ctrl reinterpreted as the platform’s primary accelerator (Modifiers::COMMAND) — ⌘ on macOS, unchanged everywhere else.

This is the convention Qt spells Qt::CTRL and the one Teksilo’s native menu bar has always applied when turning a declared chord into an NSMenuItem key equivalent. ShortcutRegistry applies it to every declared default, so an app that writes KeyStroke::ctrl(Key::F) once gets Ctrl+F on Windows and Linux and ⌘F on macOS — the same chord the menu row already advertised.

It is deliberately not applied to a user override: a chord the user captured in a settings UI is a literal statement of intent, and rewriting it would make physical ⌃F unbindable on macOS.

Idempotent, and a no-op for a chord that already names Super, so Ctrl+Super survives as the genuine ⌃⌘ two-modifier chord.

Trait Implementations§

Source§

impl Clone for KeyStroke

Source§

fn clone(&self) -> KeyStroke

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 Copy for KeyStroke

Source§

impl Debug for KeyStroke

Source§

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

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

impl<'de> Deserialize<'de> for KeyStroke

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for KeyStroke

Source§

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

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

impl Eq for KeyStroke

Source§

impl Hash for KeyStroke

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for KeyStroke

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for KeyStroke

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for KeyStroke

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<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> 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, <T as TryFrom<U>>::Error>

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.