A lightweight .NET library designed to distinguish between manual keyboard typing and rapid input sequence from physical barcode scanners (which emulate keyboard keystrokes). It measures the time elapsed between keystrokes to detect fast bursts of characters and fires event callbacks.
The solution is split into separate projects for a clean, decoupled architecture:
- InspiredCodes.BarcodeScanDetector (Core Library)
- Contains the hardware-agnostic timing buffers, the 4096-character safety limit, and the 300ms debounced cooldown logic. Target:
.NET Standard 2.0/2.1.
- Contains the hardware-agnostic timing buffers, the 4096-character safety limit, and the 300ms debounced cooldown logic. Target:
- InspiredCodes.WPF.BarcodeScanDetector (WPF Extensions)
- A wrapper that hooks into WPF's
TextInputandPreviewTextInputevents for easy registration.
- A wrapper that hooks into WPF's
- InspiredCodes.WinForms.BarcodeScanDetector (WinForms Extensions)
- A wrapper that hooks into Windows Forms'
KeyPressevents.
- A wrapper that hooks into Windows Forms'
- InspiredCodes.Blazor.BarcodeScanDetector (Blazor Extensions)
- A wrapper that provides a
BarcodeScanListenercomponent andBlazorBarcodeScanServicefor Blazor WebAssembly applications.
- A wrapper that provides a
- InspiredCodes.BarcodeScanDetector.WpfDemo
- A simple WPF demo application showcasing scan listening and debugging with a UUIDv7 fast input simulator.
- InspiredCodes.BarcodeScanDetector.WinFormsDemo
- A simple WinForms demo application demonstrating scan listening and a UUIDv7 fast input simulator.
- InspiredCodes.BarcodeScanDetector.BlazorPwaDemo
- A Blazor WebAssembly PWA demo application showcasing barcode scan interception within a web browser.
- Tests Projects
InspiredCodes.BarcodeScanDetector.Tests,InspiredCodes.WPF.BarcodeScanDetector.Tests,InspiredCodes.WinForms.BarcodeScanDetector.Tests, andInspiredCodes.Blazor.BarcodeScanDetector.Testscover the core logic, event registrations, and the 4096-character cooldown limits.
The underlying timing and cooldown state machine is documented in a BPMN file:
- CharInputStateMachine.bpmn
You can view or edit this diagram in two ways:
- Online Viewer (Zero Install): Open bpmn.io (online modeler) and drag-and-drop the
CharInputStateMachine.bpmnfile directly into your browser window. - Desktop Client: Download and open the file using Camunda Modeler.
- Add the InspiredCodes.WPF.BarcodeScanDetector NuGet package to your project.
- Register the input listener on your main window in the constructor:
public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); // Register window-level text input listening this.RegisterTextInput(); } }
- Subscribe to the
BarcodeScannedevent:ScanDetector.BarcodeScanned += (sender, e) => { // Access the scanned text string barcodeValue = e.InputText; Console.WriteLine($"Scanned: {barcodeValue}"); };
For unregistering, use this.UnRegisterTextInput().
Author: Peter Metz Contributors: Steven Lee