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");

Returns true if this KeyEvent matches this HotKey.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

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