Android Question Webview _ Keycode Problem

FrankDev

Active Member
Licensed User
Hello

I have the following problem with the Webview

how do I intercept certain keycodes that the webview does not react to them - but the keycodes are delivered to me by other means.

It is about keycodes 19,20,21,23, 89,90

Best regards
Frank
 

FrankDev

Active Member
Licensed User
I have found something on the subject,

but how do I integrate it now?

my Webview is named Webview1


B4X:
#if Java
Public class MyWebView extends WebView {


    @Override
    Public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        Return new BaseInputConnection(this, False); //this Is needed For #dispatchKeyEvent() to be notified.
    }

    @Override
    Public boolean dispatchKeyEvent(KeyEvent event) {
        boolean dispatchFirst = super.dispatchKeyEvent(event);
        // Listening here For whatever key events you need
        If (event.getAction() == KeyEvent.ACTION_UP)
            switch (event.getKeyCode()) {
                Case KeyEvent.KEYCODE_SPACE:
                Case KeyEvent.KEYCODE_ENTER:
                    // e.g. get space And enter events here
                    break;
            }
        Return dispatchFirst;
    }
}

#end if
 
Upvote 0

FrankDev

Active Member
Licensed User
Hello,

I have now tried lower case... same mistake.

'public class mywebview extends webview {'

I do not have to explain inline to which object the extension applies.

or is webview already enough to know that it is the b4a object?
 
Upvote 0

DonManfred

Expert
Licensed User
Webview is an Android Object.
There is no equivalent in B4A. The Webview in B4A is just a small wrapper around the Android-WV.

If you do not know java you should better use WebviewExtras and Chromeclient and chromesettings Objects.

For the inline java you need to add the correct imports.
 
Last edited:
Upvote 0

agraham

Expert
Licensed User
I have now tried lower case... same mistake.
It's probably a different error. The correct class name is WebView, case is important in Java, and you probably need the full class name android.webkit.WebView and even then I think this is a little too ambitious for inline Java.
 
Upvote 0

FrankDev

Active Member
Licensed User
I would like to use what is 'available'.

>WebviewExtras and Chromeclient and chromesettings Objects.<

I need the function that the webview does not react to some keys ascii 20,21,22,24 and a few others but lets them through to the activity.

is this possible with the above mentioned functions ?
 
Upvote 0

DonManfred

Expert
Licensed User
is this possible with the above mentioned functions ?
i don´t know. I never used Webview much.
But i know that - at least - most of the settings you posted here are in these objects.

this
maybe this
and this
 
Upvote 0

FrankDev

Active Member
Licensed User
I now have

public class mywebview extends android.webkit.WebView

declared. the error is now another one.

means for me that he has understood the declaration !?


expected
Public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
^
 
Upvote 0

DonManfred

Expert
Licensed User
public must still be lowercased

Where does the code come from?


Edit: @agraham was faster :D
 
Upvote 0

FrankDev

Active Member
Licensed User


B4X:
https://stackoverflow.com/questions/11429878/read-keyboard-events-in-android-webview
 
Upvote 0

DonManfred

Expert
Licensed User
Upvote 0

FrankDev

Active Member
Licensed User
I have already tried many things.
put a panel over the webview and a
Keylistener is set up. It also works as long as the webview is enabled with focus. If I grant her the focus she gets the 'keys'.

the background. i want to use the Fire TV remote control from 'mouse' and need keycode 19,20,21,22,24.

If I switch the webview to focusable = false everything works as long as I can't enter anything into the input fields.

If I switch it to focusabel = True, I cannot move the 'mouse' anymore

Translated with www.DeepL.com/Translator (free version)
 
Upvote 0

FrankDev

Active Member
Licensed User
ok... after all commands are written in small letters, the first attempt is made.

after that there is still an error.

symbol: class webview
location: package anywheresoftware.b4a.objects
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

probably the function is no longer available

#if Java

public class MyWebView extends android.webkit.WebView {


@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
return new BaseInputConnection(this, false); //this Is needed For #dispatchKeyEvent() to be notified.
}

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
boolean dispatchFirst = super.dispatchKeyEvent(event);
// Listening here For whatever key events you need
if (event.getAction() == KeyEvent.ACTION_UP)
switch (event.getKeyCode()) {
case KeyEvent.KEYCODE_SPACE:
case KeyEvent.KEYCODE_ENTER:
// e.g. get space And enter events here
break;
}
return dispatchFirst;
}
}

#end if
 
Upvote 0

agraham

Expert
Licensed User
probably the function is no longer available
Even if you could get it to compile that Java code by itself is not sufficient to do what you want. You might be able to define a derived class but you still need an instance of it to use it. I'm afraid that you require a better understanding of Java than you seem to have to implement this.
 
Upvote 0

FrankDev

Active Member
Licensed User
yes... sometimes you really want to despair.

You do a project and then you realize that a small thing becomes an unavoidable hurdle.

Who would have thought that catching a few characters from a view would become a problem that can only be solved with special knowledge ...
 
Upvote 0

agraham

Expert
Licensed User
catching a few characters from a view
If WebView was a real View then it would be no trouble. However WebView is not designed to be a local View but as a display mechanism for a remote server which is why you cannot interact with it as if it were a standard View. I don't do webby stuff so I can't really advise, and I don't know how much under your control is whatever you are viewing in the WebView. In fact is WebView the right sort of view for what you want to achieve or is there another alternative that can display HTML or rich text?
 
Upvote 0

eps

Expert
Licensed User
This really shouldn't be that difficult... I've got a web based App in B4A which passes information back to B4A using Javascript.

I think we need a little more information to help.

Are you....

Using WebView to display a specific HTML file/locally based HTML files and then use the user input to perform some B4A actions or something completely different?

Is it a game or Application?
 
Upvote 0
Top