in the interest of science, here is 1 way to demonstrate
how keystrokes behave with a webview. a zipped
example is attached.
it could be used in connection with a library. for the
purposes of a demonstration, it is standalone. there
are also other ways to achieve the same end. in fact,
in a production environment, you would most likely
need a library or know how to write your own
complete webviewclient*. but based on the
description of the problem as posted above, this
example solves that problem.
there are 2 views in the example: a webview and an edittext.
they each occupy 1/2 the screen. the idea is to show what
happens to your keystrokes when one view or the other has
the focus.
the correct way to use the example is to tap on one view
to get its focus. tap a few keys slowly. tap the
other view to gain its focus and tap a few keys
slowly. 1 or 2 keystrokes will suffice. you will see what
you need to see in the log. if you start typing wildly, the
log will quickly run off the screen, and you won't see how
the strokes are being monitored.
when the edittext is in focus, you should see the
log reporting normal typing (as expected).
when the webview is in focus, it behaves similarly,
"capturing" the keystrokes for itself. this is fine if you
are, in fact, filling in a form in the webview. but not fine
if you want to use the keyboard as a trigger to unfocus
the webview and do something else. this, i believe is
what the op was describing
you have to override that default behavior in order for your
app to see the strokes and decide if certain strokes are actually
meant for something else in your app. (this is not unlike the
shouldOverrideUrlLoading() method that some of us who use
a webview may be familiar with.)
this is done by raising an event when the webview
detects keyboard activity. instead of keeping the
strokes for itself, it will pass the stroke to your
app. if the app wants the keystroke for itself,
it returns "true" to the webview. if the app is not
interested in the keystroke, it returns "false" to
the webview. false causes the webview to keep
the keystroke for its own use, if any.
in this case, i tell the app to ignore all keystrokes
coming from the webview, except for the letter
"O" (for override). i show it in the log. i could
do something else. i could have chosen a different
key. in fact, under normal circumstances, the
magic key would not be one used in normal typing,
otherwise you would not be able to type the letter
"O", although, technically, you could intercept the
"O" and still return false, but we can leave that for
a different discussion.
*technically, it is a webview's webviewclient that
intercepts the keystroke. so you have to add a custom
webviewclient to your webview. a webview can have
only 1 webviewclient. if you use a library that supplies
its own webviewclient, you cannot add your own unless
you only want this 1 method. and you cannot create
your own webviewclient and then add a library which has
its own webviewclient. if your library exposes a
webviewclient's shouldInterceptKeyStroke() method,
read its documentation on how to handle the event in
b4a.