0

In my ios application,I want to detect return key.So i used this javaScript.

function onKeyPress(e)
{
   alert(e.keyCode);
   if (e.keyCode == 13 ) {
     window.location.href = "newline://buttonClicked";
   }
}

When I use internal keyboard I can get correct key code,but if I use external keyboard it always gives 0 value.

How can I detect correct key code from external keyboard?

lighter
  • 2,808
  • 3
  • 40
  • 59
Suravi
  • 301
  • 1
  • 7
  • 21
  • You can reference this site, http://notes.ericjiang.com/posts/333 – lighter Mar 14 '14 at 04:51
  • 1
    I'd suggest checking `e.which` to see if it has the desired value. – jfriend00 Mar 14 '14 at 04:51
  • [This post](http://stackoverflow.com/questions/10509253/javascript-ipad-return-key-event) suggests that `e.keyCode` works fine, but you have to make sure you manually apply focus to a field before the events will be available. I don't have an iPad to test, just reporting results from Google searches. – jfriend00 Mar 14 '14 at 04:57
  • Another [possibly relevant post](http://stackoverflow.com/questions/3588899/how-can-i-add-a-javascript-listener-to-capture-input-from-bluetooth-barcode-scan) about iso not firing keyboard events except on elements inside a form after they've been explicitly given focus which cannot be done via javascript and has to be done by the user directly. – jfriend00 Mar 14 '14 at 04:59

1 Answers1

1

Please check with

function onKeyPress(e)
{
   alert(e.which);

}
sagar43
  • 3,341
  • 3
  • 29
  • 49
  • 1
    Do you know this works on ios with external keyboard? Or is this just a guess? If it's just a wild guess, it has already been suggested via comment which is what is appropriate for speculative guesses that are simple. – jfriend00 Mar 14 '14 at 04:58