-
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
Tracking issue: improve Key input #3653
Comments
First, store the Then, how about providing the input value to someone who wants detailed keyboard input information in pub struct InputState, pub struct RawInput, or pub struct ViewportInfo? |
@rustbasic egui is backend agnostic, and must not depend on |
We use CC: @emilk @twitzelbos |
@emilk - Just to clarify... Splitting |
I'm not 100% convinced we should split the current |
Physical and logical keys are fundamentally different things, and in every successful system that handles both they are treated separately. They just happen to align most of the time on QWERTY. I'm working on an application where many users want to bind numpad keys separately from the number row. I would love to see egui use keyboard_types, as it looks very complete. For an example of converting winit events to a shared representation, see my key-names crate. You can try it online in Hyperspeedcube (Help → Keybinds reference to see keys in real-time, or Settings → Puzzle keybinds and click on one of the keys to see it decode scan codes). key-names also detects the user's keyboard layout on Windows and Linux, although it's not possible on web or macOS. I don't expect this from egui but it's just so that I can show the keybinds reference with the correct labels. |
for visibility, #4081 also belongs here |
The thing is non-latin keyboards have both latin and non-latin symbols printed. And when user wants to, for example, save document, they presses CTRL+ physycal "S" key, which logical key could be is some non-latin symbol. I've checked web demo, input shortcuts (CTRL+A, CTRL+Z) don't work when using Greek layout. To fix the issue, I would consider using physycal keys fallback for shortcuts processing for non-latin layouts as described here Speaking of issue After that PR is merged, I can create PR, which add physycal_key fallback for shortcuts processing for non-latin layouts |
It isn't quite the physical "S" key that is used for "Ctrl+S", though. It's the virtual "S", which happens to commonly map to the physical location for "S" on Western keyboards. And therefore, also shares the same scancode. Have a look at the Bulgarian keyboard layout, for instance: https://kbdlayout.info/kbdbulg; You might question, then, "what's the difference?" The difference is that The clear thing to do is exactly what was proposed:
The scancode is very unlikely to be what you want for the former case. The linked SO answer is wrong, as I have demonstrated with just a few samples. |
@parasyte Turkish F is a latin layout though, so the logical key will be used, and Ctrl + S will still work, even though the scancode is As a dual layout user, I think @KarKarbI4's suggestion makes a lot of sense. An overwhelming majority of non-latin keyboard users have a keyboard with QWERTY + their non-latin layout printed. This will provide a good enough support for them, instead of no support at all which is the current state. |
Changing the layout may change the virtual keys reported. It is unclear why there is any confusion on this. To add to this comment: any user may opt for the Turkish F layout, regardless of what is printed on their key caps. That is inconsequential to the layout. |
@parasyte There's no confusion about this. My comment is related to the proposed solution:
In general, I agree with it. But the proposed solution doesn't take into consideration the users of non-latin keyboard layouts. For example, the user of the Bulgarian keyboard layout will not be able to invoke the "Ctrl+S" action. Now, most users of the Bulgarian layout will also have US QWERTY or a similar layout set up. However, it's bad user experience to switch to another layout to invoke a keyboard shortcut. So I propose to make the following addition to your solution:
I think that addition makes sense because on most localized keyboards QWERTY layout is printed on keycaps alongside the local layout, so users usually expect that keyboard shortcuts work in the way I described. I hope the proposal makes more sense now. What do you think? |
There are two things going on. On the one hand, an example of a keyboard shortcut was provided for illustration without regard to i18n or l10n. And on the other hand, we are discussing keyboard events, which is only tangentially related to i18n and l10n (and accessibility in general). We can’t really discuss i18n, l10n, and a11y without also bringing up IME. And I think you’ll agree it is a large topic without a great deal of overlap with handling keyboard layouts. I would probably make an adjustment to the example keyboard shortcut that included common “save” commands in other languages to disambiguate what is really being proposed. But I am adamant that scancodes (aka physical positions) are never what is wanted for normal human interactions outside of niche cases like games. |
@parasyte Hmm, I have a feeling we have a misunderstanding here. The topic of keyboard shortcuts has very little to do with i18n. You're saying:
That's not how keyboard shortcuts usually work. No matter what system or interface language you have enabled, the "save" command is always "Ctrl+S". I use two keyboard layouts (QWERTY and ЙЦУКЕН), and I probably switch them a thousand times a day. It would drive me crazy if all the keyboard shortcuts would change depending on my current layout. So what do you do if there's no letter On this keyboard with ЙЦУКЕН layout you will still press "Ctrl+S" to save. The virtual key in this case will be Take a look at this screenshot: even though Chrome UI is in Russian, keyboard shortcut hints are still referring to the latin letters, for this exact reason: That does not mean however that we should just rely on scancodes. Like you said, in most cases that's not what normal humans want :) If I'm using Dvorak, or Turkish F, or any other non-QWERTY layout with latin letters, I still want to press the button with the letter So, to reiterate my previous comment: when a non-latin letter is pressed, we should find the corresponding letter in QWERTY layout and invoke an action for it. |
I see that my interpretation of keyboard shortcuts in various languages is far from perfect. If it is always the case that "Ctrl+S" is for saving, then there is little reason to internationalize it. But there is a misconception that the "S" is in relation to QWERTY layout. This is precisely why the Windows virtual key system uses, e.g. I think that the discussion is off the rails because the UI Events semantics have been implied on one side and platform-specific virtual key mapping on the other. Virtual key maps don't deal with Unicode at all, there isn't a |
@rustbasic I'm not sure it would be wise to just jump right in, considering how much confusion there already is with existing terminology. The differences are subtle between physical ( |
I have a need for the my first thought was this: but now I'm wondering if there's a reason not to rename mac_cmd to |
…ve (#4461) resolves #4081 (see discussion starting from #3653 (comment) for extra context) this partly restores event-emitting behaviour to the state before #3649, when shortcuts such as `Ctrl` + `C` used to work regardless of the active layout. the difference is that physical keys are only used in case of the logical ones' absence now among the named keys. while originally I have only limited this to clipboard shortcuts (Ctrl+C/V/X), honestly it felt like a half-assed solution. as a result, I decided to expand this behaviour to all key events to stick to the original logic, in case there are other workflows and hotkeys people rely on or expect to work out of the box. let me know if this is an issue.
This is great for testing how e.g. keyboard events are seen by egui: ![image](https://github.com/emilk/egui/assets/1148717/b2187060-6533-439c-9f43-fc49b8213c28) * Relevant: #3653
* Part of #3653 <!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> It was surprising to me that this key wasn't sending `Event::Key` events (only `Event::Text`), so I added a `Key` for it. Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
…ve (emilk#4461) resolves emilk#4081 (see discussion starting from emilk#3653 (comment) for extra context) this partly restores event-emitting behaviour to the state before emilk#3649, when shortcuts such as `Ctrl` + `C` used to work regardless of the active layout. the difference is that physical keys are only used in case of the logical ones' absence now among the named keys. while originally I have only limited this to clipboard shortcuts (Ctrl+C/V/X), honestly it felt like a half-assed solution. as a result, I decided to expand this behaviour to all key events to stick to the original logic, in case there are other workflows and hotkeys people rely on or expect to work out of the box. let me know if this is an issue.
This is great for testing how e.g. keyboard events are seen by egui: ![image](https://github.com/emilk/egui/assets/1148717/b2187060-6533-439c-9f43-fc49b8213c28) * Relevant: emilk#3653
* Part of emilk#3653 <!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/master/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> It was surprising to me that this key wasn't sending `Event::Key` events (only `Event::Text`), so I added a `Key` for it. Co-authored-by: Emil Ernerfeldt <emil.ernerfeldt@gmail.com>
The keyboard input in egui is limited in a couple of ways:
Event::Key
super/meta
modifier keyKeyboardShortcut
should ignoreshift
andalt
keys for logical keys (e.g.Ctrl Plus
may require pressing shift on some keyboards). See The keyboard shortcut of zoom in does not work on the JIS keyboard #3626 for moreHow can I help?
egui::Key
and follow the instructions there for adding new keysRequested keys
{
and}
Prioir art
winit
: https://docs.rs/winit/latest/winit/event/struct.KeyEvent.htmlRelevant issues
scancodes
via egui-winit #2977Ctrl
+C
/V
/X
) don't work with non-Latin keyboard layouts #4081Physical vs Logical keys
Consider someone owning a physical QWERTY keyboard:
However, they have remapped it to use Dvorak (perhaps even repainting the text on their keyboard):
If they start hitting Caps Lock and then moving to the left, the keys they will be hitting will be
The logical keys makes sense for most keyboard shortcuts - if you say "Press Cmd+S to save" in your UI, the user will be looking for the logical key "S"
The physical keys are mostly useful for games, where e.g. te physical WSAD on QWERTY moves a character, no matter what the users keymap is.
The text was updated successfully, but these errors were encountered: