ZebraDevs / datawedge-MAUI-SampleApp

Showing how to integrate Zebra Datawedge barcode readings into an existing .NET MAUI App. DW is sending readings via broadcast Intents and needs a specific profile setup which is part of this solution.
12 stars 4 forks source link

Physical key pressed event capture #2

Closed FrantisekPregis closed 4 months ago

FrantisekPregis commented 4 months ago

Hello,

is there a proper way how to capture a physical key pressed event on the Zebra MC3300 in MAUI? I have two use cases:

a) detect a physical key pressed event without having focus on an Entry (e.g. in case a blue function key is pressed, wherever in the app)

b) detect a physical key pressed event with focus in an Entry. I need this to detect the physical ENTER key pressed, because unlike in case of the virtual keyboard ENTER my bound command does not get triggered, only the UI focus moves to the next element.

I experimented with the following: https://stackoverflow.com/questions/71976350/hooking-keyboard-events-in-net-maui-specifically-android

... but this doesn´t work when there is focus in an Entry, in that case the OnKeyDown method in MainActivity doesn´t fire. So I can´t make a workaround.

my Page XAML: Entry ReturnCommand="{Binding ProcessInputCommand}" Text="{Binding Input}"

my ViewModel: [ObservableProperty] private string input;

    [RelayCommand]
    public async Task ProcessInput()
    {

// DOES NOT EXECUTE IN CASE OF PHYSICAL ENTER PRESSED (BUT DOES IN CASE OF VIRTUAL KEYBOARD ENTER CLICKED) }

I am using the MVVM Community toolkit, but I think that it is not the problem.

Maybe other users of the demo app will find this useful as well. We know how to deal with the scanner, but what about the physical keyboard?

NDZL commented 4 months ago

HI @ FrantisekPregis – I’ll put this in my backlog, I need to make some tests and get hold of a keyed device. In the meantime, see if the code I posted here https://github.com/NDZL/DURESS-BUTTON-SAMPLE inspires a solution. Br Nicola

From: FrantisekPregis @.> Sent: Tuesday, February 20, 2024 3:01 PM To: ZebraDevs/datawedge-MAUI-SampleApp @.> Cc: Subscribed @.***> Subject: [ZebraDevs/datawedge-MAUI-SampleApp] Physical key pressed event capture (Issue #2)

Hello, is there a proper way how to capture a physical key pressed event on the Zebra MC3300 in MAUI? I have two use cases: a) detect a physical key pressed event without having focus on an Entry (e. g. in case a blue function key is pressed, ZjQcmQRYFpfptBannerStart External Sender This message came from outside our organization. Please use caution before acting on the message. ZjQcmQRYFpfptBannerEnd

Hello,

is there a proper way how to capture a physical key pressed event on the Zebra MC3300 in MAUI? I have two use cases:

a) detect a physical key pressed event without having focus on an Entry (e.g. in case a blue function key is pressed, wherever in the app)

b) detect a physical key pressed event with focus in an Entry. I need this to detect the physical ENTER key pressed, because unlike in case of the virtual keyboard ENTER my bound command does not get triggered, only the UI focus moves to the next element.

I experimented with the following: https://stackoverflow.com/questions/71976350/hooking-keyboard-events-in-net-maui-specifically-androidhttps://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.com_questions_71976350_hooking-2Dkeyboard-2Devents-2Din-2Dnet-2Dmaui-2Dspecifically-2Dandroid&d=DwMFaQ&c=Qwsh1H-X9ypOoLLEcAIltRyC0Dw0FG3Mmyd56ahml5w&r=U1B3Lk8Honsy_xtgC17ZQ7saNKD_TQhFfmjOeDxJ__A&m=-FTQxG38LrhDunXkxF72ATS_6Puc1cQqE1CjdsblwzhzWIRwJXJnY4bCD5NMXSJz&s=w0U3Z9E1CFsGjY6yxwk1Ky6ozEdSV6W6Byemjiyfoos&e=

... but this doesn´t work when there is focus in an Entry, in that case the OnKeyDown method in MainActivity doesn´t fire. So I can´t make a workaround.

my Page XAML:

my ViewModel: [ObservableProperty] private string input;

[RelayCommand]

public async Task ProcessInput()

{

DOES NOT EXECUTE IN CASE OF PHYSICAL ENTER PRESSED (BUT DOES IN CASE OF VIRTUAL KEYBOARD ENTER CLICKED) }

I am using the MVVM Community toolkit, but I think that it is not the problem.

Maybe other users of the demo app will find this useful as well. We know how to deal with the scanner, but what about the physical keyboard?

— Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_ZebraDevs_datawedge-2DMAUI-2DSampleApp_issues_2&d=DwMFaQ&c=Qwsh1H-X9ypOoLLEcAIltRyC0Dw0FG3Mmyd56ahml5w&r=U1B3Lk8Honsy_xtgC17ZQ7saNKD_TQhFfmjOeDxJ__A&m=-FTQxG38LrhDunXkxF72ATS_6Puc1cQqE1CjdsblwzhzWIRwJXJnY4bCD5NMXSJz&s=dhe7dhfgXsTpcoqtrg39m6ovfngUYAmQZ8Oe0DIKPmA&e=, or unsubscribehttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe-2Dauth_ACW36NE45YAFOU4RDCUUF2LYUSUDJAVCNFSM6AAAAABDRG2IPOVHI2DSMVQWIX3LMV43ASLTON2WKOZSGE2DINBVGE2TKNQ&d=DwMFaQ&c=Qwsh1H-X9ypOoLLEcAIltRyC0Dw0FG3Mmyd56ahml5w&r=U1B3Lk8Honsy_xtgC17ZQ7saNKD_TQhFfmjOeDxJ__A&m=-FTQxG38LrhDunXkxF72ATS_6Puc1cQqE1CjdsblwzhzWIRwJXJnY4bCD5NMXSJz&s=hCAKDgTdJIg2UG7zK2I4_JuCNAaZymzvLSdMWfqiSnY&e=. You are receiving this because you are subscribed to this thread.Message ID: @.**@.>>


FrantisekPregis commented 4 months ago

OK, thanks. The physical ENTER key pressed detection when in an Entry is the main problem, it would be very helpful.

NDZL commented 4 months ago

Try this https://developer.zebra.com/content/maui-android-app-mc930b-hardware-keyboard-not-responding-p1-p2-f1-f2-keys Apply for the keys you need to capture.

NDZL commented 4 months ago

Also, this worked too

https://github.com/dotnet/maui/issues/13921#issuecomment-1559057319

image

image

NDZL commented 4 months ago

1 workaround and 1 direct solution offered.

FrantisekPregis commented 4 months ago

OK, thanks very much, I will try it out!