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 December 30, 2024 15:04
Javascript for detecting usb connected - hand held - barcode scanner input
// Author: Neel Bhanushali <[email protected]>
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 = []