Skip to content

Instantly share code, notes, and snippets.

View neelbhanushali's full-sized avatar

Neel Bhanushali neelbhanushali

View GitHub Profile
@neelbhanushali
neelbhanushali / usb-connected-hand-held-barcode-scanner-input.js
Last active April 18, 2024 22:32
Javascript for detecting usb connected - hand held - barcode scanner input
// Author: Neel Bhanushali <neal.bhanushali@gmail.com>
document.addEventListener('keydown', function(e) {
// add scan property to window if it does not exist
if(!window.hasOwnProperty('scan')) {
window.scan = []
}
// if key stroke appears after 10 ms, empty scan array
if(window.scan.length > 0 && (e.timeStamp - window.scan.slice(-1)[0].timeStamp) > 10) {
window.scan = []