Struct druid_shell::HotKey [−][src]
pub struct HotKey { /* fields omitted */ }Expand description
A description of a keyboard shortcut.
This type is only intended to be used to describe shortcuts, and recognize them when they arrive.
Examples
SysMods matches the Command key on macOS and Ctrl elsewhere:
use druid_shell::{HotKey, KbKey, KeyEvent, RawMods, SysMods};
let hotkey = HotKey::new(SysMods::Cmd, "a");
#[cfg(target_os = "macos")]
assert!(hotkey.matches(KeyEvent::for_test(RawMods::Meta, "a")));
#[cfg(target_os = "windows")]
assert!(hotkey.matches(KeyEvent::for_test(RawMods::Ctrl, "a")));None matches only the key without modifiers:
use druid_shell::{HotKey, KbKey, KeyEvent, RawMods, SysMods};
let hotkey = HotKey::new(None, KbKey::ArrowLeft);
assert!(hotkey.matches(KeyEvent::for_test(RawMods::None, KbKey::ArrowLeft)));
assert!(!hotkey.matches(KeyEvent::for_test(RawMods::Ctrl, KbKey::ArrowLeft)));Implementations
Create a new hotkey.
The first argument describes the keyboard modifiers. This can be None,
or an instance of either SysMods, or RawMods. SysMods unify the
‘Command’ key on macOS with the ‘Ctrl’ key on other platforms.
The second argument describes the non-modifier key. This can be either
a &str or a KbKey; the former is merely a convenient
shorthand for KbKey::Character().
Examples
use druid_shell::{HotKey, KbKey, RawMods, SysMods};
let select_all = HotKey::new(SysMods::Cmd, "a");
let esc = HotKey::new(None, KbKey::Escape);
let macos_fullscreen = HotKey::new(RawMods::CtrlMeta, "f");Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for HotKey
impl UnwindSafe for HotKey
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span, returning an
Instrumented wrapper. Read more
pub fn round_from(x: T) -> T
pub fn round_from(x: T) -> T
Performs the conversion.
pub fn round_into(self) -> U
pub fn round_into(self) -> U
Performs the conversion.
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more