How to get keypresses from a webview

NeoTechni

Well-Known Member
Licensed User
Longtime User
In my program, I draw all the UI elements myself, except for a webview control
When the webview is visible, it absorbs all the keypress events. I don't want it to. Is there any way I can get keypress events from it? I'd like to be able to let is absorb arrow keys sometimes but not all.
 

KZero

Active Member
Licensed User
Longtime User
i have no idea if its possible in b4a

but u may use some tricks

in html there is onkeypress Event you can use it and every onkeypress make the page title = the pressed key (it all from the html)

now read the page title from b4a to determine the pressed key

i hope it help
 
Upvote 0

NeoTechni

Well-Known Member
Licensed User
Longtime User
Got it.
B4X:
MyWebViewExtras.addJavascriptInterface(webview1, "B4A")
     MyWebViewExtras.addWebChromeClient(webview1, "")
where MyWebViewExtras is a WebViewExtras object, and webview1 is your webview.
Then all you need to do is add this to the HTML
<SCRIPT>document.onkeypress = function (e) { B4A.CallSub('Activity_KeyPress', false, e.keyCode); };</SCRIPT>
 
Upvote 0
Top