-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
[Spec] Key Handling #11797
Comments
Note that it would break shortcuts every single language with non-latin alphabet, like armenian, arabic, various cyrilic scripts, etc. With those layouts the localized key would be a non-latin character while shortcuts are still using the latin one written on the same physical key. |
I'm wondering how this is handled on the web? Does anyone with experience of this have any input? (I use a QWERTY keyboard so I'm ignorant of such things). I notice that in the vscode issue they say:
|
Pressing "Z" on: US keymap: Have fun |
To be clear, I wasn't wondering about how keys are represented on the browser, instead about how web apps go about handling shortcuts on different keyboards. |
After discussing with @kekekeks he says that this spec will break access key handling on non-latin scripts so I'm not sure we should go ahead with it any further. I'm not sure what the way forward should be. I'd assumed that the w3c would have taken this into account, but it seems not? If someone knowledgeable about this subject could help out, it would be appreciated, otherwise I'll close this issue in a few weeks. |
Would be useful to know which exact hotkeys are handled with different keymaps |
Testing macOS Chrome, |
It should probably be either a
I think it should set both
That means that the existing linked issues won't be fixed, which are real ones. On the browser and with an AZERTY keyboard, I can't use Ctrl+A or Ctrl+Z inside a textbox in the control catalog. Granted, some shortcuts still exist - with the wrong keys - which is better than no shortcut at all for non latin scripts, but still very inconvenient. Note that some are still impossible in this environment: I should use Ctrl+W instead of Ctrl+Z to undo, but that will close the browser tab instead :) (Not related to Avalonia but there are still a lot of games - it's a bit better nowadays than a decade ago - that force WASD movement without being able to remap the keys, resulting in being unplayable on AZERTY layouts, unless you're an octopus). I'm also interested in knowing how shortcuts are usually handled (badly, I assume) by various apps for non latin scripts. |
The apps use the corresponding latin key and it always just works.
We probably need to have some layot-specific logic to handle that or copy what Chrome does |
I think that regardless of the considerations about shortcuts, etc., having access to the raw untranslated scan codes would be useful in many situations. (For example, I'm working on a PC emulator which needs to pass host scan codes through to the VM.) |
Ok, so I think the latest on this is:
|
The Problem
We have a problem with our
KeyEventArgs
. The problem is that on win32 theKey
is localized to the current keyboard layout whereas on macOS and Linux it is not.The root of this problem is something that vscode and Chrome went through a while ago and is well described in this issue:
microsoft/vscode#17521
Taking the relevant parts of that issue:
The
KeyEventArgs.Key
property which we inherited from WPF represents a virtual key, but that concept is a win32 concept.This results in the problem that on win32, our
Key
property reflects the key after mapping from a scan code to a virtual key code, but on other platforms it represents a scan code.Scan codes are not localized so we end up with the situation where on win32 the
Key
takes the keyboard layout into account but on macOS and Linux it doesn't:The Solution
The W3C spec for
KeyboardEvent
is a one place to look for inspiration as they've already gone through this.They have the following attributes on their
KeyboardEvent
:keyCode
is similar to what we currently havekey
holds a key attribute value corresponding to the key pressed. The key attribute is not related to the legacy keyCode attribute and does not have the same set of values. The values are defined herecode
holds a string that identifies the physical key being pressed. The value is not affected by the current keyboard layout or modifier state, so a particular key will always return the same value (i.e. it is the scan code). The values are defined hereThis looks like decent place to start. The only complication is that the
key
attribute is kind of a combined enum (can be a string likeEnter
,Backspace
etc) and unicode key (e.g.A
,%
,あ
) string. That doesn't translate well to C# where enums are not typically strings.The Proposal
KeyEventArgs.Key
as its behavior differs between operating systemsScanCode
enumKeyEventArgs.ScanCode
property to describes the physical key being pressed which is not affected by the current keyboard layout or modifier statechar? KeyCharacter
property which describes the unicode character that the key represents after mapping to the current keyboard layout, if it existsKey? SpecialKey
property which describes special keys not represented by a unicode character, such as (taken from the W3C spec):Questions
Tab
be used instead of the\t
characterKeys
enum suitable forSpecialKey
?KeyEventArgs
going to be confusing? Can we tweak the API to make falling into the pit of success a little easier?The text was updated successfully, but these errors were encountered: