Key Event issues with Android Devices

Occasionally people try and do interesting things with the Android Platform, and sometimes they work out well, and sometimes they work out poorly.  An example of this is the Sony Xperia Play, and another example is the failing Google TV platform.  Both of which have really weird keys in their UI that need to be supported, but don’t lend themselves well to regular development.

The main issue with Android and the KeyEvent is that the KeyCode mapping is entirely arbitrary and does not correspond to JavaScript key mapping.  For example, 0 corresponds to 7 on Android, but is 48 in Javascript.  This would normally be consumed by the WebView and web developers working on PhoneGap applications would normally not have to worry about this issue.  However, there’s issues such as the keys not being consumed, such as the UP, DOWN, LEFT and RIGHT events on Google TV.  In this case, users would have to use hacky Java work-arounds to fire custom events, which may or may not work properly on Android.

Of course, we don’t have a good answer to this yet.  One is to keep a mapping between JS and the Android keys, and another is to fire a custom event for these custom keys, since they only exist on Android.  We’re still discussing this now on the Cordova list, and I’m not sure what the right answer is because they have their pros and cons.  I am definitely on the custom event, since you should really only be using these platform-specific keys on that platform.

One thought on “Key Event issues with Android Devices

  1. Interesting notion.
    We’re currently implementing a custom keyboard, which sends custom commands on our custom HTML control (Using a hidden input to receive and process commands), but also has to work on ‘regular’ input text components.
    However, the ‘delete’ key, which works differently over our custom control (Via sending specific codes into a proxy hidden input), doesn’t put a character in our proxy input – So we do not know when user selects that button.
    Since we do not want to implement two delete buttons in the same keyboard (One regular and one custom), custom events could be our saviour!
    Did you advance with that? Is there another possible solution?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>