ClaimedBarcodeScanner.DataReceived() 事件作为 WebView 控件 (UWP) 的键盘输入
ClaimedBarcodeScanner.DataReceived() event as keyboard input for WebView control (UWP)
我已经成功地为霍尼韦尔 Dolphin 75e 设备编写了一个应用程序,同时具有嵌入式和外部指环扫描器 运行 Windows 10 Mobile Enterprise。
关于如何在 Internet 上处理 UWP 中的条码扫描器,resources 有很多。然而,他们都在扫描一些基于文本的用户控件,如下所示:
private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e)
{
// Add a data receive event handler.
claimedScanner.DataReceived += claimedScanner_DataReceived;
}
async void claimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
{
// Update the UI with the data received from the scan.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// Read the data from the buffer and convert to string.
var scanDataLabelReader = DataReader.FromBuffer(args.Report.ScanDataLabel);
ScenarioOutputScanDataLabel.Text = scanDataLabelReader.ReadString(args.Report.ScanDataLabel.Length);
var scanDataReader = DataReader.FromBuffer(args.Report.ScanData);
ScenarioOutputScanData.Text = scanDataReader.ReadString(args.Report.ScanData.Length);
ScenarioOutputScanDataType.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType);
});
}
但我需要的是扫描仪在我的 WebView
控件上充当键盘:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView Source="http://google.co.uk"/>
</Grid>
当我不在我的应用程序中明确使用(不声明)扫描仪并保留默认设置,就像它对任何应用程序在全球范围内所做的那样,扫描仪会在我的 WebView
中完成我需要的工作。但是因为我必须在我的应用程序中使用 assign/claim 不同的扫描仪,所以我必须让它像键盘一样工作,这意味着,当 WebView
中的任何用户输入字段获得焦点时,我只需将输入扫描到其中.
Here 我发现了一个类似的问题,虽然它很容易解决,因为每次扫描只有 URL(搜索词)中的参数必须不同。
更新:我还考虑了一个解决方法,这样即使我离开应用程序,我的应用程序也会声明扫描仪并保留它。在那种情况下,我可以打开浏览器,导航到我的网络应用程序并使用所需的扫描仪。不幸的是,在我离开应用程序后,除了嵌入式扫描仪之外的所有扫描仪似乎都被处理掉了。即使我没有明确处置它们。
None Honeywell 提供的测试应用程序似乎也保留了声明。
好的,看来我现在明白它是如何工作的了。对于我需要的,我不需要创建任何声明并启用特定扫描仪的应用程序,因为它会将扫描仪从 default 楔形模式切换到 POS 模式。
Dolphin 75e user guide 中描述了这两种模式之间的区别。
Dolphin 75e models running Windows 10 IoT Mobile Enterprise has two scan modes, Wedge mode and POS mode. In Wedge mode bar code data is inserted into the keyboard interface, as if the bar code data was entered using the keyboard. POS mode implements Microsoft Point of Service interface. In POS mode, barcode data is sent to an application via the Microsoft defined APIs.
Scan wedge mode is enabled by default. The 75e remains in wedge mode until POS application starts and claims the scanner. The terminal only switches back to wedge mode when the POS application releases its claim on scanner.
所以,我只需要将 scanner config file 放入 /Documents/Profile 文件夹,指定我想在 Wedge 模式下使用的扫描仪。不幸的是,我的 USB HID 指环扫描仪无法进入楔形模式...
Note that wedge mode is not supported for USB HID scanner in v66.4.0.638, or v66.4.0.569.
所以在经历了所有这些努力之后,我发现如果有人想为自定义 web 应用程序使用 75e 扫描仪,或者扫描到 Excel 电子表格 - 他的唯一的选择是使用嵌入式扫描仪,默认情况下以楔形模式运行。
并且如果你想使用USB HID扫描仪,那么你只能将它用于专门开发的应用程序,实现微软定义的APIs。所以基本上,您将只能扫描到特定的用户控件 - 文本块、输入字段 - 如我的第一个 post.
所示
更新:从版本 66.4.0.718 开始,USB HID 扫描仪也可以在楔形模式下使用!
我已经成功地为霍尼韦尔 Dolphin 75e 设备编写了一个应用程序,同时具有嵌入式和外部指环扫描器 运行 Windows 10 Mobile Enterprise。
关于如何在 Internet 上处理 UWP 中的条码扫描器,resources 有很多。然而,他们都在扫描一些基于文本的用户控件,如下所示:
private async void ScenarioStartScanButton_Click(object sender, RoutedEventArgs e)
{
// Add a data receive event handler.
claimedScanner.DataReceived += claimedScanner_DataReceived;
}
async void claimedScanner_DataReceived(ClaimedBarcodeScanner sender, BarcodeScannerDataReceivedEventArgs args)
{
// Update the UI with the data received from the scan.
await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
// Read the data from the buffer and convert to string.
var scanDataLabelReader = DataReader.FromBuffer(args.Report.ScanDataLabel);
ScenarioOutputScanDataLabel.Text = scanDataLabelReader.ReadString(args.Report.ScanDataLabel.Length);
var scanDataReader = DataReader.FromBuffer(args.Report.ScanData);
ScenarioOutputScanData.Text = scanDataReader.ReadString(args.Report.ScanData.Length);
ScenarioOutputScanDataType.Text = BarcodeSymbologies.GetName(args.Report.ScanDataType);
});
}
但我需要的是扫描仪在我的 WebView
控件上充当键盘:
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<WebView Source="http://google.co.uk"/>
</Grid>
当我不在我的应用程序中明确使用(不声明)扫描仪并保留默认设置,就像它对任何应用程序在全球范围内所做的那样,扫描仪会在我的 WebView
中完成我需要的工作。但是因为我必须在我的应用程序中使用 assign/claim 不同的扫描仪,所以我必须让它像键盘一样工作,这意味着,当 WebView
中的任何用户输入字段获得焦点时,我只需将输入扫描到其中.
Here 我发现了一个类似的问题,虽然它很容易解决,因为每次扫描只有 URL(搜索词)中的参数必须不同。
更新:我还考虑了一个解决方法,这样即使我离开应用程序,我的应用程序也会声明扫描仪并保留它。在那种情况下,我可以打开浏览器,导航到我的网络应用程序并使用所需的扫描仪。不幸的是,在我离开应用程序后,除了嵌入式扫描仪之外的所有扫描仪似乎都被处理掉了。即使我没有明确处置它们。
None Honeywell 提供的测试应用程序似乎也保留了声明。
好的,看来我现在明白它是如何工作的了。对于我需要的,我不需要创建任何声明并启用特定扫描仪的应用程序,因为它会将扫描仪从 default 楔形模式切换到 POS 模式。
Dolphin 75e user guide 中描述了这两种模式之间的区别。
Dolphin 75e models running Windows 10 IoT Mobile Enterprise has two scan modes, Wedge mode and POS mode. In Wedge mode bar code data is inserted into the keyboard interface, as if the bar code data was entered using the keyboard. POS mode implements Microsoft Point of Service interface. In POS mode, barcode data is sent to an application via the Microsoft defined APIs.
Scan wedge mode is enabled by default. The 75e remains in wedge mode until POS application starts and claims the scanner. The terminal only switches back to wedge mode when the POS application releases its claim on scanner.
所以,我只需要将 scanner config file 放入 /Documents/Profile 文件夹,指定我想在 Wedge 模式下使用的扫描仪。不幸的是,我的 USB HID 指环扫描仪无法进入楔形模式...
Note that wedge mode is not supported for USB HID scanner in v66.4.0.638, or v66.4.0.569.
所以在经历了所有这些努力之后,我发现如果有人想为自定义 web 应用程序使用 75e 扫描仪,或者扫描到 Excel 电子表格 - 他的唯一的选择是使用嵌入式扫描仪,默认情况下以楔形模式运行。
并且如果你想使用USB HID扫描仪,那么你只能将它用于专门开发的应用程序,实现微软定义的APIs。所以基本上,您将只能扫描到特定的用户控件 - 文本块、输入字段 - 如我的第一个 post.
所示更新:从版本 66.4.0.718 开始,USB HID 扫描仪也可以在楔形模式下使用!