Macro zng_app::shortcut_macro
source · macro_rules! shortcut_macro { (Super) => { ... }; (Shift) => { ... }; (Ctrl) => { ... }; (Alt) => { ... }; ($Key:tt) => { ... }; ($($MODIFIER:ident)|+ + $Key:tt) => { ... }; ($StarterKey:tt, $ComplementKey:tt) => { ... }; ($StarterKey:tt, $($COMPLEMENT_MODIFIER:ident)|+ + $ComplementKey:tt) => { ... }; ($($STARTER_MODIFIER:ident)|+ + $StarterKey:tt, $ComplementKey:tt) => { ... }; ($($STARTER_MODIFIER:ident)|+ + $StarterKey:tt, $($COMPLEMENT_MODIFIER:ident)|+ + $ComplementKey:tt) => { ... }; }
Expand description
Creates a Shortcut
.
This macro input can be:
- A single
ModifierGesture
variant defines aShortcut::Modifier
. - A single
Key
variant defines aShortcut::Gesture
without modifiers. - A single
char
literal that translates to aKey::Char
. ModifiersState
followed by+
followed by aKey
orchar
defines a gesture with modifiers. Modifier combinations must be joined by|
.- A gesture followed by
,
followed by another gesture defines aShortcut::Chord
.
Note that not all shortcuts can be declared with this macro, in particular there is no support for Key::Str
and KeyCode
, these shortcuts must be declared manually. Also note that some keys are not recommended in shortcuts,
in particular Key::is_modifier
and Key::is_composition
keys will not work right.
§Examples
use zng_app::shortcut::{Shortcut, shortcut};
fn single_key() -> Shortcut {
shortcut!(Enter)
}
fn modified_key() -> Shortcut {
shortcut!(CTRL+'C')
}
fn multi_modified_key() -> Shortcut {
shortcut!(CTRL|SHIFT+'C')
}
fn chord() -> Shortcut {
shortcut!(CTRL+'E', 'A')
}
fn modifier_release() -> Shortcut {
shortcut!(Alt)
}