-
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
Open
rustbasic
wants to merge
38
commits into
emilk:master
Choose a base branch
from
rustbasic:patch36
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
f0b7737
Update memory.rs
rustbasic 3b98d7f
Update epi_integration.rs
rustbasic af5a7bb
Update memory.rs
rustbasic 7f66b56
Update memory.rs
rustbasic 6396c4a
Update epi_integration.rs
rustbasic 9fe42ff
Merge branch 'emilk:master' into master
rustbasic d7673fe
Merge branch 'emilk:master' into master
rustbasic a7edc53
Merge branch 'emilk:master' into master
rustbasic 2432784
Merge branch 'emilk:master' into master
rustbasic 9b6209b
Merge branch 'emilk:master' into master
rustbasic f3687f6
Merge branch 'emilk:master' into master
rustbasic 78880de
Merge branch 'emilk:master' into master
rustbasic 01ba2ec
Merge branch 'emilk:master' into master
rustbasic 0ae2451
Merge branch 'emilk:master' into master
rustbasic e6c84ce
Merge branch 'emilk:master' into master
rustbasic 821dff0
Update epi_integration.rs
rustbasic eecfafd
Merge branch 'emilk:master' into master
rustbasic cbb5ac7
Merge branch 'emilk:master' into master
rustbasic 07b5143
Merge branch 'emilk:master' into master
rustbasic 3313633
Update epi_integration.rs
rustbasic 90b968c
Merge branch 'emilk:master' into master
rustbasic 13af44f
Merge branch 'emilk:master' into master
rustbasic 5d95f09
Merge branch 'emilk:master' into master
rustbasic 4be440a
Merge branch 'emilk:master' into master
rustbasic 1ef0e10
Merge branch 'emilk:master' into master
rustbasic 6541324
Merge branch 'emilk:master' into master
rustbasic 8abc161
Merge branch 'emilk:master' into master
rustbasic 1b21742
Merge branch 'emilk:master' into master
rustbasic 052bb68
Merge branch 'emilk:master' into master
rustbasic b1a0b89
Update input_state.rs
rustbasic e99b446
Update input_state.rs
rustbasic 8f66fdf
Update input.rs
rustbasic 9525357
Merge branch 'emilk:master' into patch36
rustbasic ff1eab8
Merge branch 'emilk:master' into patch36
rustbasic d292a6d
Merge branch 'emilk:master' into patch36
rustbasic 7daae80
Merge branch 'emilk:master' into patch36
rustbasic eba4eeb
Merge branch 'emilk:master' into patch36
rustbasic 35b38ba
Merge branch 'emilk:master' into patch36
rustbasic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,6 +393,16 @@ impl InputState { | |
self.consume_key(modifiers, logical_key) | ||
} | ||
|
||
/// Verifies that all modifier keys (e.g. Ctrl, Alt) are not pressed. | ||
pub fn modifiers_not_pressed(&self) -> bool { | ||
self.modifiers.is_none() | ||
} | ||
|
||
/// 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() | ||
} | ||
|
||
/// Was the given key pressed this frame? | ||
/// | ||
/// Includes key-repeat events. | ||
|
@@ -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 commentThe 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
} |
||
self.keys_down.contains(&desired_key) | ||
&& self.keys_down.len() == 1 | ||
&& self.modifiers_not_pressed() | ||
} | ||
|
||
/// 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 commentThe 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()
} |
||
self.keys_down.contains(&desired_key) && self.modifiers_not_pressed() | ||
} | ||
|
||
/// Is the given key currently held down? | ||
pub fn key_down(&self, desired_key: Key) -> bool { | ||
self.keys_down.contains(&desired_key) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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