9

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

7
  • 2
    $(document).on('keyup', $.mobile.pageContainer, function() { }); try it. or $('body').on('keyup', function () { });
    – Omar
    Jul 5, 2013 at 17:05
  • here's a working example. If this is what you need, let me know. jsfiddle.net/Palestinian/sG9n8
    – Omar
    Jul 5, 2013 at 17:22
  • For me, both statements & the answer below make it work only with focus on the input field - but if the input field is hidden, no keyboard input in captured. any pitfalls I overlooked? Jul 5, 2013 at 17:23
  • Check the demo I made.
    – Omar
    Jul 5, 2013 at 17:27
  • Demo works on nicely on Desktop Safari, but not in Mobile Safari though. Will dig deeper in some hours. Jul 5, 2013 at 17:30

2 Answers 2

1

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

$(document).bind('keyup', function(e) {
    alert('testing');
});
0

You can also simply position the element off-canvas, without needing to alter its DOM/CSS visibility state.

<style> .inputValue{position:absolute;left:-99999px} </style>
<input type="text" class="inputValue" autofocus="autofocus"/>

And then at any given point when you require the input's value you call the below script.

<script> $('.inputValue').val(); </script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.