Created
December 12, 2018 08:16
-
-
Save bagaskarawg/b75765076198a4288565291ccbaefa6d to your computer and use it in GitHub Desktop.
Listen for barcode scanning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var chars, pressed; | |
pressed = false; | |
chars = []; | |
$(window).on('keypress', function(e) { | |
if (e.which !== 13) { | |
chars.push(String.fromCharCode(e.which)); | |
} | |
if (pressed === false) { | |
setTimeout(function() { | |
var barcode; | |
if (chars.length >= 5) { | |
barcode = chars.join(""); | |
} | |
chars = []; | |
return pressed = false; | |
}, 300); | |
} | |
return pressed = true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment