When I use a barcode scanner in a normal notepad, it scans a code like this: 2000000415369
.
When I create an input field in HTML
and put focus into that field and scan a barcode, it still outputs the correct code.
Now when I create a javascript listener to capture the code, to make sure, in javascript, that the input came from a barcode scanner, the keyPress event.which
string outputs a lot more characters than what is described above. I get this in my console output:
0|5|0|2|0|4|8|0|0|4|8|0|0|4|8|0|0|4|8|0|0|4|8|0|0|4|8|0|0|5|2|4|0|4|9|1|0|5|3|5|0|5|1|3|0|5|4|6|0|5|7|9|
where every keycode has been changed into its keyboard value. When you compare the two scanned codes, you'll see that the correct barcode is contained within the longer scanned code. Every correct character is separated by 3 additional numbers:
050 2 048 0 048 0 048 0 048 0 048 0 048 0 052 4 049 1 053 5 051 3 054 6 057 9
Does anybody have any clue what is going on here? I'm at a complete loss why the keyPress event would capture more numbers pressed than the input field. I also tested with a normal keyboard and typing would result in only the correct pressed character to be outputed to the console.
Below is the javascript code I use for capturing the keyPress event:
$(document.body).on('keypress',function(e){
aScannedEan.push(String.fromCharCode(e.which));
});
console.log(aScannedEan.join("|"));
I have an HTML table and I want to mark cells by adding a class to the highest and lowest value of each column. I have found a few related questions here, but the code misbehaves. var $table = $("#...
I have an HTML table and I want to mark cells by adding a class to the highest and lowest value of each column. I have found a few related questions here, but the code misbehaves. var $table = $("#...
First of all, word of explanation: I'm new to all this Meteor stuff so it might be a stupid question. In my Meteor code I have a template: <template name="hour_form"> <form id="add_hours"&...
First of all, word of explanation: I'm new to all this Meteor stuff so it might be a stupid question. In my Meteor code I have a template: <template name="hour_form"> <form id="add_hours"&...
I'm new to JavaScript server developement. I recognized the "mean" stack. MongoDB, Express.js, Angular.js and node.js. Where is the difference between express.js and anguar.js and do I need both at ...
I'm new to JavaScript server developement. I recognized the "mean" stack. MongoDB, Express.js, Angular.js and node.js. Where is the difference between express.js and anguar.js and do I need both at ...
I have a form with a bunch of text elements, some of which have a data attribute set. I want to loop through all the elements that have that attribute, extracting the attribute. I've created a ...
I have a form with a bunch of text elements, some of which have a data attribute set. I want to loop through all the elements that have that attribute, extracting the attribute. I've created a ...