Skip to content

Commit 48b40a2

Browse files
madsmtmpyfisch
authored andcommitted
Add helper methods on KeyState
These allow you to use KeyState without having to import it.
1 parent 3cb4720 commit 48b40a2

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ impl KeyState {
5555
Self::Up => "keyup",
5656
}
5757
}
58+
59+
/// True if the key is pressed down.
60+
pub const fn is_down(self) -> bool {
61+
matches!(self, Self::Down)
62+
}
63+
64+
/// True if the key is released.
65+
pub const fn is_up(self) -> bool {
66+
matches!(self, Self::Up)
67+
}
5868
}
5969

6070
/// Keyboard events are issued for all pressed and released keys.

src/shortcuts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl<T> ShortcutMatcher<T> {
8585
return self;
8686
}
8787
if modifiers == self.modifiers && key.match_key(&self.key) {
88-
if self.state == KeyState::Down {
88+
if self.state.is_down() {
8989
self.value = Some(f());
9090
}
9191
self.matched = true;

0 commit comments

Comments
 (0)