-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
These functions check whether a key has been pressed alone. #4328
base: master
Are you sure you want to change the base?
Conversation
typo
|
||
/// Was only the given key pressed this frame, with no modifiers? | ||
pub fn key_pressed_only(&self, desired_key: Key) -> bool { | ||
self.num_presses(desired_key) > 0 && self.modifiers_not_pressed() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if one day key_pressed
might be modified -we could easily forget this - fix this using the function here, too
pub fn key_pressed_only(&self, desired_key: Key) -> bool {
key_pressed(desired_key) && self.modifiers_not_pressed()
}
@@ -416,6 +426,18 @@ impl InputState { | |||
.count() | |||
} | |||
|
|||
/// Is the given key currently held down and no other keys are held down, including modifier keys? | |||
pub fn key_down_exclusive(&self, desired_key: Key) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
pub fn key_down_exclusive(&self, desired_key: Key) -> bool {
key_down(desired_key) && self.keys_down.len() == 1
}
} | ||
|
||
/// Is the given key currently held down and no other keys are held down? | ||
pub fn key_down_only(&self, desired_key: Key) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned above:
pub fn key_down_only(&self, desired_key: Key) -> bool {
key_down(desired_key) && self.modifiers_not_pressed()
}
These functions check whether a key has been pressed alone.
Add Functions :
modifiers_not_pressed()
key_pressed_only()
key_down_only()
key_down_exclusive()
For Test Code :