pub struct HotKey { /* private fields */ }
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§
source§impl HotKey
impl HotKey
sourcepub fn new(mods: impl Into<Option<RawMods>>, key: impl IntoKey) -> HotKey
pub fn new(mods: impl Into<Option<RawMods>>, key: impl IntoKey) -> HotKey
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§
source§impl PartialEq<HotKey> for HotKey
impl PartialEq<HotKey> for HotKey
impl Eq for HotKey
impl StructuralEq for HotKey
impl StructuralPartialEq for HotKey
Auto Trait Implementations§
impl RefUnwindSafe for HotKey
impl Send for HotKey
impl Sync for HotKey
impl Unpin for HotKey
impl UnwindSafe for HotKey
Blanket Implementations§
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>
§impl<T> RoundFrom<T> for T
impl<T> RoundFrom<T> for T
§fn round_from(x: T) -> T
fn round_from(x: T) -> T
Performs the conversion.
§impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
impl<T, U> RoundInto<U> for Twhere
U: RoundFrom<T>,
§fn round_into(self) -> U
fn round_into(self) -> U
Performs the conversion.