pub struct KeyStroke {
pub key: Key,
pub modifiers: Modifiers,
}Expand description
A single keyboard chord: a key plus its modifiers.
Fields§
§key: Key§modifiers: ModifiersImplementations§
Source§impl KeyStroke
impl KeyStroke
pub fn new(key: Key, modifiers: Modifiers) -> Self
Sourcepub fn ctrl(key: Key) -> Self
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.
pub fn ctrl_shift(key: Key) -> Self
Sourcepub fn command(key: Key) -> Self
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.
Sourcepub fn command_shift(key: Key) -> Self
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.
pub fn alt(key: Key) -> Self
Sourcepub fn with_command_convention(self) -> Self
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.