-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Keyboard mapping: add mapped key string to raw key event #4447
Conversation
Getting the error:
So that's perhaps a compat dealbreaker.. |
OSX side not implemented. Don't really know how to bite the objc+com(?)+sharpgen thing #_# (sorry |
How would that work with various IME systems once they are implemented? |
Also, I don't see any the user API changes, only internal raw event args. |
Yeah just realized that. Adding it to |
I think IME input events should be routed as text input messages plus |
see: yatli/fvim#36 |
@kekekeks uwp has Key and OriginalKey (unmapped) props https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.input.keyroutedeventargs?view=winrt-19041 |
And I have not looked detailedly on original issue, but probably Character prop is needed as well https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.input.characterreceivedroutedeventargs?view=winrt-19041 (note, it is from another event in uwp). Not sure, does Avalonia have it, can't check now. |
_owner, | ||
RawKeyEventType.KeyDown, | ||
KeyInterop.KeyFromVirtualKey(ToInt32(wParam), ToInt32(lParam)), | ||
WindowsKeyboardDevice.Instance.StringFromVirtualKey((uint)ToInt32(wParam)), |
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.
This needs to be corrected. StringFromVirtualKey
takes ctrl
and alt
into consideration and will translate a key into a control sequence.
@maxkatz6 UWP seems to provide virtual key mapping, not characters. |
@kekekeks I think I can give a single requirement that cannot be satisfied with the current framework: to detect
|
Before introducing such an API that doesn't exist in UWP/WPF, we need to
Otherwise we are bound to miss something important. |
For Qt, see QString convertKey(const QKeyEvent& ev) noexcept
{
QString text{ ev.text() };
... |
What's the status on this PR? |
instead of modifying RawKeyEventArgs, isn't it better to create an extesion method like this? public interface IKeyMapper
{
string ToKeyString(RawKeyEventArgs arg, CultureInfo culture);
...
}
public static string? ToKeyString(this RawKeyEventArgs args, CultureInfo culture = null )
{
var mapper = AvaloniaLocator.GetService<IKeyMapper>();
return mapper?.ToKeyString(arg, culture);
} |
|
Locator in this case is useful for injecting the specific keymapper by platform, we could implement macOsKeyMapper, iOSKeyMapper, etc ...
that's true, but any platform could subclass RawKeyEventArgs and add platform-specific information. Only the keymapper of the specific platform would see the difference. |
Which is not a valid reason to add something to service locator. Stuff like that should be resolved via the platform layer or embedded into the event args via the same platform layer. Service locator is pure evil that's here because it's been there in the early days (and it's also kinda troublesome to manage rendering-related stuff without a locator). |
I think that there is no absolute evil or absolute good, it all depends on the use made of it. |
Yep, you are right. I misleaded point of PR back then. I just found that in UWP there is relatively new event for controls - UIElement.CharacterReceived There is also old global event with another arguments CoreWindow.CharacterReceived Upd: although it's very similar to our TextInput event. |
Another approach is to provide API to query "what text this keystroke will produce". type KeystrokeEffect =
| Key of Key // keyboard mapping agnostic special keys e.g. Enter, Backspace etc.
| Translated of char // keyboard mapping specific key translation
| ImePreEdit of string // IME preedit update
| ImeCommit of string // IME commit, clears preedit and input text
| ImeCancel of string // IME cancel, clears preedit and convert the preedit to input text We just need to keep the relevant platform-specific keystroke data, in sync with the IME states. I can give it a try if you guys think this is reasonable. |
Has any progress been done since the last message? |
The core team has designed and implemented the IME model, I have to read it and adjust my proposal so not to break it :) |
I have the same problem as this user of fvim and I'm looking forward to a fix that I can use in my project. Adding keyboard mapping would benefit a lot of projects! |
Closing this PR for inactivity. Ping me if this is updated accordingly. |
No description provided.