How to get keydown and keyup events on Kindle Fire HD using jQuery Mobile

I can get a keydown event to launch a new Kindle Fire HD tablet to delete and enter keys.

I use the built-in Silk browser. I see that the keydown event is firing on Google. How did they earn?

If I go to a keyboard testing website, for example http://unixpapa.com/js/testkey.html in the Silk browser, it also fails. Does anyone have a workaround for this?

$("#simpleSearch_input").keydown(function(evt) { alert("keydown"); }); 
+4
source share
1 answer

You need to use the "input" event instead of the "keyup"

Keyboard event order (HTML5) - keydown-> keypress-> input-> keyup.

The input event will lack some properties that are also passed to keyup, such as keyCode / metaKey / shiftKey / altKey

I used:

var inputEV = 'oninput' in the window? 'input': 'keyup'

to identify the event that triggered my call autocomplete in the Silk browser.

The jQuery code used by jsfiddle to validate it.

 (function($){ $(document).ready(function(){ var inputEV = 'oninput' in window ? 'input' : 'keyup'; $('#listen').on(inputEV,function(event){ $('#show').val($('#show').val()+'\n'+event.type); console.log('--- input event ----'); for(var v in event.originalEvent){ if(event.hasOwnProperty(v)){ console.log(v+' |--> '+event[v]); } } }) //just added to see what Silk listens for on the keyup event $('#listen').on('keyup',function(event){ $('#show').val($('#show').val()+'\n'+event.type+' | which --> '+event.which); console.log('--- keyup event ----'); for(var v in event.originalEvent){ if(event.hasOwnProperty(v)){ console.log(v+' |--> '+event[v]); } } }) }); })(jQuery); 

jsfiddle link:

http://jsfiddle.net/visionmonster/eJJna/embedded/result/

As in the original question, I could only get a Silk browser for listening to delete / enter keys

HTML5 Specification: http://www.whatwg.org/specs/web-apps/current-work/#handler-oninput

0
source

All Articles