-
Notifications
You must be signed in to change notification settings - Fork 248
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
Fix ctrl or win interfering with character inputs #149
Fix ctrl or win interfering with character inputs #149
Conversation
Hey! Thanks for the PR. Could you provide more details on the issue? I don't understand what exactly prevents users to enter |
On (most?) AZERTY PC keyboard, the character
|
A path toward the resolution of this issue would be to add tests for preventing the issue you're describing : "no wrong character input when hotkey is pressed". |
After some research, I think looking into egui winit integration (and maybe others) can be enlightening:
|
After a more thorough reading of the code, I'm starting to doubt my keyboard... I want to emphasize that the egui examples are allowing me to input an I'll fire up a debugger when I have time and report here my findings. |
With my fix as of 6ab53df: on PC:
variables and event received on windows for a altgr-0:
on Mac:
events received on mac for a ctrl-A:
|
Following my tests, I think my lastest comment https://github.com/mvlabat/bevy_egui/pull/149/files#r1117103529 would satisfy best worlds. Please tell me if you are aware of problematic hotkeys or anything! I asked for aditional reviews on egui discord given the difficulty to test for side effects: https://discord.com/channels/900275882684477440/904461220592119849/1078692430687248444 |
Does this fix work on Windows? (I'm on macOS) I would assume that when processing the received characters for |
src/systems.rs
Outdated
@@ -240,7 +240,7 @@ pub fn process_input_system( | |||
} | |||
} | |||
|
|||
if !ctrl && !win { | |||
if !mac_cmd { |
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.
Does it make sense to express it as?
if !mac_cmd { | |
if !command { |
Which means ctrl
in Windows and cmd
in macOS.
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.
in theory I agree, but the problem is that ctrl is true when using altrgr (maybe that's the actual root issue 🤔) I guess it wouldn't work then.
(see #149 (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.
https://en.wikipedia.org/wiki/AltGr_key#Ctrl+Alt
Ah well, I guess that's why. AltGr implies ctrl+alt
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.
Then that could be discarded? It's command
only if it's ctrl
, not ctrl+alt
?
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.
only if it's
ctrl
, notctrl+alt
how about !command || ctrl && alt && cfg!(target_os = "windows")
?
I believe this behaviour is specific only to Windows. Please correct me if I'm wrong, but I believe that in Linux altgr
doesn't map to ctrl+alt
(I don't have a way to test that atm).
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.
According to my manual testing, your suggested change works fine for windows and mac 🎉
I might be able to test the behaviour on a spare raspberry pi but not sure when.
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 meant that maybe alt
can be included in the command
variable computation?
Then here just leave !command
. I mean this because what happens in windows if you do altgr+c
/altgr+v
? Does it work as as copy/paste since altgr
maps to ctrl+alt
(if I understood correctly).
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.
Following the changes in #156, I mean to integrate it like this:
let command = if cfg!(target_os = "macos") {
mac_cmd
} else {
// Only when `ctrl` is pressed; this skips `altgr` which maps to `ctrl+alt`
ctrl && !alt
};
And then just doing !control
should work, no? It'll ignore shortcuts, and in macOS chars like ctrl+a
will skip because the inner !event.char.is_control()
check. But, in macOS this will allow ctrl+_
usages that actually produce some character, like: ctrl+´ => "
.
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.
@doup I'd prefer the altgr
behaviour to be limited just to Windows, as I haven't found any proof that it works like that on any other platform. I haven't invested enough time to understand how ctrl+_
works in MacOS, but on my ANSI MacBook keyboard I haven't found a single button that produced a character in combination with ctrl+_
.
I'll stick to this solution for the time being, but I'm open to revisiting it if any other issues are found.
Interestingly, yes it works on windows correctly (copies the selected text without printing additional ones), I expected the same as you. |
@doup it seems to me that the behaviour mac users would expect is for a hotkey to do nothing. For example, when I press So I think we are ok if in the scenario when a user presses |
Uhmm, that's true, The thing is that while processing For example let skip_character_input = if cfg!(target_os = "macos") { mac_cmd || ctrl } else { false }; Although, it would be interesting to see if there is a way to discern [1]: |
Prrfff, I noticed that on my keyboard Other stuff I've found:
Hahaha, this is weird. Anyway, it's probably OK to just ignore all |
I'm building an app where I need users to enter a "at sign" (@), and input text is not allowing me to do that.
Looks like the issue is from bevy_egui.
My changes appear to fix it, but I didn't make a bigger background check on why that condition was there originally.
Other context as to how I ended up to this solution: https://discord.com/channels/691052431525675048/1072569924972728320