-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Add a case-insensitive check for Key::Character value
#11691
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
Conversation
|
Welcome, new contributor! Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨ |
|
This particular fix would be a bit of a bummer for me. |
It seems that you need Wouldn't it be better to provide both always UPPERCASE |
key_without_modifiers in convert_keyboard_inputto_uppercase in convert_logical_key
to_uppercase in convert_logical_keyKey::to_uppercase_character()
ThierryBerger
left a comment
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.
I think this has value 👍 ; and low surprise code for users.
A user can still match like to avoid clone
match event.logical_key {
Key::Character(c) if c.to_uppercase().to_string() == "A") =>
...
Added an alternative, or perhaps having both functions could be a viable option? |
Key::to_uppercase_character()Key::Character value
Is there a way to use |
|
We could remove the P.S. Closing this out, as the linked issue has been closed and I don't think this is the right approach to the ultimate problem. |
There is no such thing, it's not trivial to consistently support |
Objective
Fixes #11689 if logical letter keys should remain consistent regardless of external factors.
Reporting both lowercase and UPPERCASE logical letter keys is adding a burden on us to make shortcuts in the games.
Solution
Apply the upstream suggestion.- Usekey_without_modifiersinconvert_keyboard_inputforconvert_logical_key.- Useto_uppercaseto all OSs because some of them don't supportkey_without_modifiers.Add
Key::to_uppercase_character().Returns an uppercase version if
selfis aKey::Character.Otherwise, returns a
Cloneofself.For example:
Expose the
SmolStr::eq_ignore_ascii_case(&str)toKey.Returns true if
selfis aKey::Character(character_self)andcharacter_selfis an ASCII case-insensitive match with the givencharacter.Otherwise, it means they are not matched or
selfis not aKey::Character.For example:
Changelog
Before
The main Bevy after the merge of #10702 occurs the situation that all letter logical keys, for example, the 'W' key is reporting a lowercase 'w' normally and an uppercase 'W' when CapsLock is activated or Shift is pressed.
If dealing with both case, we have to repeat the following boilerplate code:
After
Now in this case, we have: