Search code examples
androidcordovakindle-fire

How to capture "Go" key in a Phonegap application running on a Kindle Fire?


My web app has a handler that listens for what key is pressed and responds accordingly.

handler: function(event) {
    if (event.which === Constants.ENTER_KEY) {
        ...
    }
}

Constants.ENTER_KEY is 13

This is my input field (in JSX):

<input id="some-id" onKeyDown={this.handler} />


Now, I'm converting my web app to a mobile app that runs on a Kindle Fire.
Instead of an "Enter" key, I now have "Go". Examining that event, I see that

which: 0, charCode: 0, keyCode: 0, key: 'Unidentified'.

In fact, every key I tested results in event.which: 0

How do I capture "Go"?

Since I believe FireOS is built on top of Android, I'll investigate Android solutions. I will update with what I find out.

Edit:
The key needs to be detected in a <input>. Maybe I should wrap a <form> around it and listen for an onSubmit...

Edit 2:
I posted a solution, but would like an explanation regarding why it works. Thanks.


Solution

  • Wow, this is bizarre.

    Changing onKeyDown to onKeyPress fixes it. Not sure why.

    which: 13, charCode: 13, keyCode: 0, key: 'Enter'

    Edit:
    After changing to onKeyPress, it seems like handler is only entered when I press "Go".