This works for me when running as a web app, should work ok when compiled as a phonegap app:
If keycapture = "off" Then Exit Function
keyval = e.keyCode
It doesn't catch Function keys since most are intercepted by the browser, so I don't use these keys in an app. This function gets all key presses regardless of form being displayed or whether an input box or text area are being used. So I filter the Call to dosomething by knowing what form or what input object is being used. I can toggle the capture by setting the variable keycapture. I use a single modal form to enter text with only one input object available in the entire app (a separate one is used for textarea input). By using this method I know exactly what data field the user is typing in the app.
A little tricky, but in this particular app I am reproducing a program written many years ago in DOS that used only the keyboard for navigation, no mouse or touch. Works quite well. But I'm not using a black background, well.... maybe I should to make it more authentic.