If you are using an Entry
you don't need to read all keys, instead you can subscribe to Completed
event witch is fired when Enter
is readed into the Entry.
So many barcode readers can be configured to insert Enter
as last part of barcode readed.
MyBarcodeReader()
{
MyBarCodeEntry.Completed += MyBarCodeEntry_Completed;
}
private void MyBarCodeEntry_Completed(object sender, EventArgs e)
{
/// Do your JOB
}
EDIT JUL 8 2023:
Unfortunately the Completed event appears to be unpredictable and this was causing false positive reading. So I had to change my approach and decided to add a listener to my Entry binding source and analize if the results ends with an \r. This solve all my false positives.
Something like this
public static readonly BindableProperty FilterProperty =
BindableProperty.Create(nameof(Filter), typeof(string), typeof(QuickSearch), null, propertyChanged: OnFilterChanged);
public string Filter
{
get { return (string)GetValue(FilterProperty); }
set { SetValue(FilterProperty, value); }
}
private static async void OnFilterChanged(BindableObject bindable, object oldValue, object newValue)
{
if (bindable is QuickSearch q)
await q.ProccessFilter();
}
private void ProccessFilter()
{
CapturedCode = Filter?.Replace("\r", "") ?? string.Empty;
Regex regex = new(SearchParms.RegexTemplate);
if (Filter == null || regex.IsMatch((string)CapturedCode))
{
if (Filter != null && Filter.EndsWith("\r"))
await ProccessCodeCompleted();
return;
}
}
Maybe this is caused by maui bugs. (Maui is a pretty good tool but still so buggy)