Barcode Scanner Emulator
HID Keyboard Wedge Explained
Keyboard wedge is the default operating mode for the overwhelming majority of barcode scanners. This guide explains what it is, how it works at the USB level, and what it means for testing your application.
What is a keyboard wedge?
The term originates from older serial-port scanners that were literally "wedged" between a keyboard and its computer port, intercepting the keyboard signal and injecting scanned characters into it. Modern scanners no longer need physical wedging — the phrase now refers to any scanner that presents scanned data as if it came from a keyboard, regardless of connection type.
USB HID and keyboard emulation
USB defines a Human Interface Device (HID) class specifically for keyboards, mice, and similar input devices. When a scanner enumerates on USB as a HID keyboard, the OS loads its generic, built-in keyboard driver — no scanner-specific driver is required. The scanner's firmware converts each decoded character into the HID keycode a physical keyboard would send, and reports are delivered over the same interrupt transfer mechanism used by any USB keyboard.
How your application sees scanner input
Fast burst of keystrokes vs. human typing: a scanner sends the full payload as a rapid sequence of keydown/keyup pairs, typically completing in under a second regardless of barcode length.
No mouse events: scanners in HID keyboard mode never generate pointer, click, or focus events. If your field is not focused when the scan happens, the input is lost or goes to whatever element does have focus.
No paste events: because the data arrives as individual keystrokes rather than a clipboard operation, paste event handlers will not see scanner input, and input masks that only listen for paste will silently miss it.
Keyboard layout issues
Why wrong characters appear: the scanner maps decoded characters to HID keycodes using its own configured keyboard layout. If that layout does not match the OS keyboard layout, characters can be transposed — a classic symptom is digits or punctuation scanning as the wrong character on QWERTY vs AZERTY systems.
Locale mismatch: this is a scanner-side configuration issue, not a software bug. Most scanners support locale switching via configuration barcodes printed in their manual, and fixing it means reprogramming the scanner to match the OS locale, not changing application code.
Prefixes and suffixes
Scanners commonly support configurable prefix and suffix sequences around the payload. The most common suffix values are ENTER (CR, 0x0D), TAB (0x09), and occasionally a full CR+LF pair. Prefixes are less common but are sometimes used to route scans to specific fields in legacy terminal applications.
Limitations for browser testing
A browser cannot see raw USB HID packets, cannot enumerate connected HID devices as a scanner specifically (outside of the WebHID API, which most scanners don't expose data through), and cannot distinguish a HID keyboard-mode scanner from an actual keyboard. Only browser-visible keyboard events (keydown, keyup, keypress) are accessible to JavaScript, which is exactly what the tools on this site inspect.
Related
Use the Keyboard Event Tester to inspect raw keyboard events, or read the ENTER vs TAB Suffixes guide for suffix configuration details.