I have some generic code that listens for a certain sequence of keypresses and then registers that a physical barcode attached to a piece of paper has been scanned:
var pressed = false;
var chars =[];
$(window).keypress(function(e){
if ((e.which>=65 && e.which <=90) || (e.which == 93) || (e.which >=97 && e.which <=122) || (e.which >=48 && e.which <=57)) {
chars.push(String.fromCharCode(e.which));
}
if (pressed == false) {
setTimeout(function() {
if (chars.length >= 13) {
var barcode = chars.join("");
prefix = barcode[0] + barcode[1] + barcode[2];
}
chars = [];
pressed = false;
process(barcode)
},500);
}
pressed = true;
});
On different pages the action that needs to be performed is different and I still need this listener to be able to process the scan. I am not sure how to design this sort of functionality in the Ember realm and was looking for some advice on what to do from experienced Ember devs.