Skip to content

Commit

Permalink
support an array of target devices
Browse files Browse the repository at this point in the history
  • Loading branch information
majorsilence committed Nov 1, 2024
1 parent 7803e0b commit d8ff1d8
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions TownSuite.BarcodeScanner/UsbBarcodeScannerRawInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public class UsbBarcodeScannerRawInput : NativeWindow, IUsbBarcodeScanner
private readonly Timer _timer = new Timer();
private readonly Keys _endKey;
private readonly string _endKeyStr;
private readonly string _targetDeviceId;
private readonly string[] _targetDeviceIds;
private bool _isCapturing = false;
private readonly IntPtr hwd;

Expand All @@ -83,25 +83,29 @@ public class UsbBarcodeScannerRawInput : NativeWindow, IUsbBarcodeScanner

#region Constructor

public UsbBarcodeScannerRawInput(Form frm) : this(frm, Keys.Enter, string.Empty)
public UsbBarcodeScannerRawInput(Form frm) : this(frm, Keys.Enter, null)
{
}

public UsbBarcodeScannerRawInput(Form frm, Keys endKey, string targetDeviceId)
public UsbBarcodeScannerRawInput(Form frm, Keys endKey, string[] targetDeviceIds)
{
hwd = frm.Handle;
_targetDeviceId = targetDeviceId;
_targetDeviceIds = targetDeviceIds;
_endKey = endKey;
_timer.Interval = 20;
_timer.Tick += (sender, args) => _keys.Clear();
_timer.Stop();
AssignHandle(hwd);
}

public UsbBarcodeScannerRawInput(Form frm, string endKey, string targetDeviceId)
public UsbBarcodeScannerRawInput(Form frm, string endKey, string targetDeviceIds) : this(frm, endKey, new string[] { targetDeviceIds })
{
}

public UsbBarcodeScannerRawInput(Form frm, string endKey, string[] targetDeviceIds)
{
hwd = frm.Handle;
_targetDeviceId = targetDeviceId;
_targetDeviceIds = targetDeviceIds;
_endKeyStr = endKey;
_timer.Interval = 20;
_timer.Tick += (sender, args) => _keys.Clear();
Expand Down Expand Up @@ -328,11 +332,13 @@ private bool IsTargetDevice(RAWINPUTHEADER header)
string normalizedDeviceName = deviceName.Replace("\\", "#");

// Compare the device name with the target device ID
if (normalizedDeviceName.Contains(_targetDeviceId))
foreach (var deviceId in _targetDeviceIds)
{
return true;
if (normalizedDeviceName.Contains(deviceId))
{
return true;
}
}

}
finally
{
Expand Down

0 comments on commit d8ff1d8

Please sign in to comment.