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.