A robust, IE6-compatible JavaScript library for handling Barcode Scanner and Keyboard inputs in web applications.
- Dual Mode Detection: Automatically distinguishes between manual keyboard input and high-speed scanner input.
- IE6 Compatible: Validated support for legacy browsers (IE6+), including
json2.jsintegration for JSON parsing. - Event Separation: Uses
keypressfor accurate character capture (fixing legacykeydownissues with symbols like{or") andkeydownfor control keys. - Buffering & validation: Built-in input buffering, length limits, and custom validation.
- Throttle Control: Prevents duplicate submissions.
- Rich Callbacks: Hooks for Scan Start, Input, Complete, Error, etc.
Simply include the scripts in your HTML file.
<!-- For IE6/7 support -->
<script src="json2.js"></script>
<!-- Main Library -->
<script src="main.js"></script>var scanner = new ScannerKeyboardInput({
// Configuration
maxCodeLength: 8,
scanTimeout: 200, // ms
// Callbacks
onScanComplete: function(code) {
console.log("Scanned Code:", code);
// Do ajax post...
},
onKeyboardComplete: function(code) {
console.log("Keyboard Input:", code);
},
onError: function(msg) {
alert("Error: " + msg);
}
});
// Automatically bind events to document
scanner.init();
// Or bind to a specific element
// scanner.init(document.getElementById('app'));| Option | Type | Default | Description |
| Prefix | Type | Default | Description |
|---|---|---|---|
maxCodeLength |
Number | 8 |
Max length for keyboard input buffering. |
scanTimeout |
Number | 2000 |
Timeout to reset scanner buffer (ms). |
throttleInterval |
Number | 3000 |
Time to wait before allowing duplicate submission (ms). |
scanStartKeyCode |
Number | 219 |
KeyCode for scanner start char (default: {). |
scanEndKeyCode |
Number | 221 |
KeyCode for scanner end char (default: }). |
shouldSubmit |
Function | null |
Custom validator. Return false to cancel submission. |
onScanStart(): Triggered when scanner start sequence is detected.onScanInput(val): Triggered on every char during scan.onScanComplete(code): Triggered when scan is finished and parsed.onKeyboardInput(char, loc, fullCode): Triggered on manual key press.onKeyboardComplete(code): Triggered when manual input reachesmaxCodeLength.onError(msg): Triggered on JSON parse error or other failures.
- Chrome, Firefox, Safari, Edge (Modern)
- Internet Explorer 6, 7, 8, 9+
MIT