'Capture KeyDown or KeyPress in .NET MAUI (Windows)

I am working on a barcode reader app for Android and Windows. On Android, I receive a system broadcast for every barcode scanned, but on Windows the typical configuration is a keyboard entry sent from the barcode scanner. So what I am trying to do is capture the KeyDown/KeyPress event so that I can add all characters received into a temporary string and then submit to my app as a "barcode read event" as soon as "Enter" is received.

However, I am unable to find KeyDown/KeyPressed events in any of the controls. Is that possible at all? If so, where do I look? The closest (I think) I have gotten is this description of how to use the App lifecycle events: https://docs.microsoft.com/en-us/dotnet/maui/fundamentals/app-lifecycle

Thanks and best regards,

Joerg.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source