-
-
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
Limit IFocusManager API, extend IInputElement API, remove focus static members from public API #11407
Conversation
cc @amwx |
You can test this PR using the following package version. |
I think the only thing missing from the API is a way to track focus changes globally: previously one could do that by subscribing to |
You can test this PR using the following package version. |
The whole API will probably change with #7607 anyway? If I'm interpreting "preparing" correctly, that PR is on the table again, which is great, as focus needs a good overhaul! |
That should be handled by |
Indeed! Thanks for the pointer, it turns out that indeed that extra |
Hi, I may be missing something here, but I feel like this regression is now fully blocking our project from upgrading to 0.11. If this isn't the case there's no reason to read on, and I'd really appreciate an explanation as to how this is achieved now that InputManager is no longer accessible. Otherwise... We have an in-app keyboard control for a touchscreen "POS-like" application which needs to be able to simulate key-presses, and not just text input. We can't use an OS-provided onscreen keyboard as it takes up way too much screen real estate on our product, and show/hiding the OS keyboard is also not an ideal solution for many reasons, the slowness on Windows being one of them. We could previously set our keyboard control (and the buttons that comprise it) to Focusable="False" which preserves keyboard focus on the input element selected by the user. This meant we could throw keyboard events from the top and let Avalonia (or the target control) handle the routing and handling. As far as I can tell, this is now no longer possible, and we're going to have to have handlers for each InputElement implementation somewhere, and track which element currently has focus. The second part of this issue is that (as far as I can tell) we can no simulate special keys/combos, or directly invoke some of the behaviours attributed to them. That means that actions like copy, paste, return/enter (not newline), etc, and the functionality they invoke have to also be handled individually, or will be completely unavailable to us without custom implementations of TextBox, NumericUpDown, etc. Please tell me I'm wrong, as we've been really excited to move to v11.0 as is fixes a lot of issues we currently have with 10.x. Also, I can't be the only one who is going to run into this issue surely? Apologies in advance if this is the result of a misunderstanding on my side! |
Simulating input events in 11.0 works exactly as it does in WPF and UWP - by raising a routed event:
This was the intended way of sending events since 0.1.0. For tracking focused element updates you can use |
The key bindings are a valid concern though, we'll investigate how to make those to be triggerable by user code. |
Thanks for the quick response! I'm not sure how we ended up with the InputManager solution then... must have been an ill-informed/outdated SO answer I'm sure! |
I am still unable to obtain input. Is there a more detailed sample code? |
I'm in the same boat as @qfmee, and I can't seem to simulate any input via the method you described. I've put all of the following logic inside the Keyboard control itself for now while I'm testing: In Keyboard control's constructor:
In an event handler for key presses on our keyboard:
"this" is my keyboard control. I've tried:
_currentElement is not null, and is set to the TextBox I have focused as expected. Am I missing something here? |
After further testing, I've found the following works for the text input:
I'm still struggling to send key events though. |
@storzem should work similar, I guess? Can you show which code does not work for you? |
EDIT: Best would be to open a new Q&A discussion and ideally have a minimal sample showing what you have so far. |
The Source should be set to the focused element not to your keyboard control |
Like this: _currentElement?.RaiseEvent(new KeyEventArgs the Control key can take effect, but the text can't, such as Key.A,Key.B........... |
Yeah, I found for alphanumerics (and possibly more), you need to use:
EDIT: Removed a reference to my own key class |
Apologies for the late reply, work has been super busy! Based on what @qfmee said last, it seems like it might just be a case of alphanumeric keys being ignored on the KeyDownEvent. I'm assuming this is to avoid duplicate input, as TextInputEvent handles text.... |
Thanks. This method allows for text input, but non English text, such as Chinese, cannot be input! |
What does the pull request do?
Keeping in mind that we have a very long list of refactorings related to the focus system in Avalonia, we really need to limit it now with something that won't be broken mid 11.x.
Breaking changes
Yes.
Fixed issues
Fixes partially #11381
Prepares for #7607