I'm currently toying with a basic webpage to act as a kiosk app.
The page will contain a basic form.
Attached to the PC directly is a barcode scanner in 'keyboard' mode. The barcode scanner automatically appends a char "13" at the end of each string. (I do have the option to also prefix a character to the string if required)
The scanner is to allow the user to scan a barcode (if they have it) - which can then be used to perform a looking.
Of course, it is possible that the user doesn't have a barcode - they may just have a number, so they should be able to manually key the number to.
This scenario actually presents a number of challenges! I don't think that I am going to find a barcode scanner that has a driver that can be accessed via Javascript. (ie I can' send messages to enable and disable the scanner).
I really don't want to code this in any .Net - PHP only..
What I would like to do is somehow redirect any input that comes from the barcode scanner to a hidden field. Any other input keyed manually by the user should appear in the current element that has focus.
The following JQuery script looks pretty good. (https://github.com/kabachello/jQuery-Scanner-Detection)
<input id="userInput" type="text" autofocus/>
<br>
<div class="test">
<input id="scannerInput" type="text" value="barcodescan" autofocus/>
</div>
$(document).scannerDetection({
//https://github.com/kabachello/jQuery-Scanner-Detection
timeBeforeScanTest: 200, // wait for the next character for upto 200ms
avgTimeByChar: 40, // it's not a barcode if a character takes longer than 100ms
endChar: [13],
//preventDefault: true, //this would prevent text appearing in the current input field as typed
onComplete: function(barcode, qty){
alert(barcode);
} // main callback function
});
I've set up a fiddle here: https://jsfiddle.net/upnorthal/4fuyvjnv/
The above Javascript is actually extremely accurate in detecting whether the data has been keyboard typed or from the scanner.
If I uncomment the line
'''
//preventDefault: true,
''''
I can prevent text appearing in the text field that has focus. What I need to have happen is for the text to appear if it was keyed manually.
Any ideas how I can do this? In psuedo code it sounds like
- disable default behaviour for currently focused input field
- save any key board entry to a field
if no scan was detected - then append the value stored back to the current field
if a scan was detected - then the text must be appended to the hidden field.
Al