1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//! keyseq macros for bevy game engine
use Modifiers;
use ;
/// Check left and right modifier keys to populate bit flags.
/// Convenience wrapper to avoid `Modifier::from(&*input)` shenanigans due to
/// resource type `Res<>` wrapper.
/// Short hand notation describes a physical key chord as `(modifiers: `[Modifiers]`,
/// key_code: `[bevy::input::keyboard::KeyCode][keycode]`)`.
///
/// Specify a key and any modifiers.
///
/// ```
/// use keyseq::{Modifiers, bevy::pkey};
/// use bevy::input::keyboard::KeyCode;
/// assert_eq!(pkey! { A }, (Modifiers::NONE, KeyCode::KeyA));
/// assert_eq!(pkey! { Ctrl-A }, (Modifiers::CONTROL, KeyCode::KeyA));
/// assert_eq!(pkey! { Alt-A }, (Modifiers::ALT, KeyCode::KeyA));
/// assert_eq!(pkey! { Shift-A }, (Modifiers::SHIFT, KeyCode::KeyA));
/// assert_eq!(pkey! { Super-A }, (Modifiers::SUPER, KeyCode::KeyA));
/// assert_eq!(pkey! { Ctrl-Alt-; }, (Modifiers::CONTROL | Modifiers::ALT, KeyCode::Semicolon));
/// assert_eq!(pkey! { Ctrl-Alt-Semicolon }, (Modifiers::CONTROL | Modifiers::ALT, KeyCode::Semicolon));
/// assert_eq!(pkey! { 1 }, (Modifiers::NONE, KeyCode::Digit1));
/// assert_eq!(pkey! { Alt-1 }, (Modifiers::ALT, KeyCode::Digit1));
/// ```
///
/// More than one key will cause a panic at compile-time. Use keyseq! for that.
///
/// ```compile_fail
/// # use keyseq::bevy::pkey;
/// fn too_many_keys() {
/// let _ = pkey! { A B };
/// }
/// ```
///
/// This macro does not ensure the key names exist but the compiler will.
///
/// ```compile_fail
/// use keyseq::bevy::pkey;
/// use bevy::input::keyboard::KeyCode;
/// let (mods, key) = pkey! { Alt-NoSuchKey }; // KeyCode::NoSuchKey does not exist.
/// ```
/// [keycode]: https://docs.rs/bevy/latest/bevy/prelude/enum.KeyCode.html
pub use bevy_pkey as pkey;
/// Short hand notation describes a sequence of physical key chords as
/// `[(modifiers: `[Modifiers]`, key: `[bevy::input::keyboard::KeyCode][keycode]`)]`.
///
/// [keycode]: https://docs.rs/bevy/latest/bevy/prelude/enum.KeyCode.html
pub use bevy_pkeyseq as pkeyseq;
/// Short hand notation describes a logical key chord as `(modifiers:`
/// [Modifiers]`, key: `[bevy::input::keyboard::Key][key]`)`.
///
/// [key]: https://docs.rs/bevy/latest/bevy/prelude/enum.Key.html
/// ```
/// use keyseq::{Modifiers, bevy::lkey as key};
/// use bevy::input::keyboard::Key;
///
/// assert_eq!(key!{ a }, (Modifiers::NONE, Key::Character("a".into())));
/// assert_eq!(key!{ Ctrl-a }, (Modifiers::CONTROL, Key::Character("a".into())));
/// assert_eq!(key!{ Alt-a }, (Modifiers::ALT, Key::Character("a".into())));
/// assert_eq!(key!{ Shift-a }, (Modifiers::SHIFT, Key::Character("a".into())));
/// assert_eq!(key!{ Super-a }, (Modifiers::SUPER, Key::Character("a".into())));
/// assert_eq!(key!{ Ctrl-Alt-; }, (Modifiers::ALT |
/// Modifiers::CONTROL, Key::Character(";".into())));
/// ```
///
/// This does have a limitation though because the macro does not do reverse look
/// ups from character to name.
///
/// ```compile_fail
/// # use keyseq::{Modifiers, bevy::lkey};
/// use bevy::input::keyboard::Key;
/// assert_eq!(lkey!{ Ctrl-Semicolon }, (Modifiers::CONTROL, Key::Character(";".into())));
/// ```
pub use bevy_lkey as lkey;
/// Short hand notation describes a sequence of logical key chords as `[(modifiers:
/// `[Modifiers]`, key: `[bevy::input::keyboard::Key][key]`)]`.
///
/// [key]: https://docs.rs/bevy/latest/bevy/prelude/enum.Key.html
pub use bevy_lkeyseq as lkeyseq;