Skip to content

Instantly share code, notes, and snippets.

View marcossaore's full-sized avatar
😀

Marcos Soares marcossaore

😀
View GitHub Profile
@marcossaore
marcossaore / usb-connected-hand-held-barcode-scanner-input.js
Created September 20, 2023 02:44 — forked from neelbhanushali/usb-connected-hand-held-barcode-scanner-input.js
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 = []