unoplatform / uno

Open-source platform for building cross-platform native Mobile, Web, Desktop and Embedded apps quickly. Create rich, C#/XAML, single-codebase apps from any IDE. Hot Reload included! 90m+ NuGet Downloads!!
https://platform.uno
Apache License 2.0
8.81k stars 707 forks source link

[WASM] Hardware Keyboard Events (PreviewKeyUp/Down) #1595

Open carldebilly opened 5 years ago

carldebilly commented 5 years ago

Hardware keyboard events

Current situation

Missing implementations

greenorb007 commented 5 years ago

I understanded the thing to do but i am currently new in the open source and don't know how to get started with the issues and how to resolve them, so please help me in this.

kazo0 commented 4 years ago

@greenorb007 I'd love to look at this one and walk you through it so you can see how to get Uno up and running and how to submit a pull request!

greenorb007 commented 4 years ago

ok so you are going to help me on this right! @kazo0

kazo0 commented 4 years ago

@greenorb007, sure. To start, you should read through the docs for setting up the Uno solution and try and get the samples app up and running. We can take a look at the issue from there.

MartinZikmund commented 4 years ago

Reserving this one for @weitzhandler as part of one of the Hacktoberfest meetups 👍

MartinZikmund commented 3 years ago

Although we attempted to start on this issue, it is more complex due to the tunneling of the Preview events.

trungnt2910 commented 2 years ago

Hi,

This issue looks interesting. While I did have some prior experience with debugging Uno Platform pointer events, I would appreciate it if you pointed me to the files that are responsible for the KeyUp and KeyDown events (I can see TypeScript implementations for pointerup and similar events, but not for keys).

Furthermore, would you mind if you explain about the complexity that prevented your last attempt on this issue?

Thanks.

MartinZikmund commented 2 years ago

Adding @dr1rrb as the authority here 😁

dr1rrb commented 1 year ago

There are several difficulties:

  1. The **Preview**Key<Up|Down> are tunneling events (a.k.a. "Capture phase / phase 1" in web), while so far we have only bubbling events in uno (a.k.a. "Phase 3" in web). tunelling events are raised down from the root element down to the target/focused element. (cf. diagram here: https://javascript.info/bubbling-and-capturing#capturing). This means that we don't really have helpers to manage "handled" events (i.e. when a parent control prevents sub elements to get the event), treat the distinction between natively handled vs. managed handled events ... and the need to still propagate the events for handlers that are flagged with the "handledEventsToo" (cf. https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.uielement.addhandler).
  2. While on wasm we can almost match those events to native events, it's not necessarily the case for other platforms. The difficulty then would be to properly support the handling / cancelling of those events to make sure to avoid flicker in text inputs.

We could imagine that as a first step we support those events only on wasm, but I think that we do need to make sure to treat the handled flag as it's the main interest of those events IMO

Bubbling and capturing
UIElement.AddHandler(RoutedEvent, Object, Boolean) Method (Microsoft.UI.Xaml) - Windows App SDK
Adds a routed event handler for a specified routed event, adding the handler to the handler collection on the current element. Specify handledEventsToo as true to have the provided handler be invoked even if the event is handled elsewhere.
DierkDroth commented 1 year ago

@dr1rrb @MartinZikmund handling .PreviewKeyDown on WASM (only) definitely would help.

I reviewed my code and found that I would need it for AutoSuggestBox. On all other occations I was able to replace it simply by .KeyDown.