I'm building a site that after the page is loaded, needs to listen for a particular keyboard string.
The event I am interested in is actually a scanner scanning an object, but it presents to the site as keyboard input, of the form ~XXX~.
I see jQuery has a keypress() event that you can bind to a particular object.
But how can I listen for general keyboard input, after $(document).ready?
Try this:
$(function() {
$(window).keypress(function(e) {
var key = e.which;
//do stuff with "key" here...
});
});
See it in action on jsFiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With