Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch keyboard input without visible input field in JavaScript

Situation:

  • HTML5 with jQuery Mobile on iPad (EDIT: HTML5 page in a PhoneGap app)
  • external keyboard attached
  • text input field is hidden, no visible input field
  • no focus on text input field -> no soft keyboard shown

Goal:

  • catch keyboard input without showing & focusing on a text input field
  • Keyboard input is are variable phrases (e.g. name1, object2, phrase3)
  • Just start typing and the page should capture that typing

--> How can I detect the keyboard input into the hidden input field?

I know the keydown / keypress / keyup events, however they seem to require a visible input field

like image 420
Michael Schmidt Avatar asked Jul 05 '13 17:07

Michael Schmidt


1 Answers

You can bind the event to the document like this:-

$(document).bind('keyup', function(e) {
    alert('testing');
});
like image 180
Vivek Sadh Avatar answered Sep 23 '22 17:09

Vivek Sadh