You can use javascript to set a disabled text field's value, and to get keystroke event data through document.onkeydown = function(e) { ... }
. No need for hidden divs.
I assume you have other fields on your page, which will make it difficult to know when to capture the card reader data. Are you fortunate enough that your credit card reader sends some unique first character(s) so you know the keyboard events are coming from the reader and not user keystrokes? If so, then you can listen for those particular key strokes so you don't have to worry about setting focus. Otherwise maybe consider a button like "Read Credit Card" that has an on("click")
function set to read the next xx digits.
Here's some debugging code you can use to see if your reader sends any unique characters that you can listen for:
document.onkeydown = function(d) {
console.log( d.which ? d.which : window.event.keyCode);
};
It's conceivable that there's some other unique event information when the reader is used. Maybe check the device's manual.