Search code examples
webviewkeyboardjavafxtouchscreen

JavaFX WebView / WebEngine show on-screen-keyboard automatically for each text input


Background/Context:

I am developing touch screen based kiosk application with JavaFX. The app integrates browser – WebView. The problem is that all user inputs have to be made through on screen keyboard (SW keyboard)

It would be nice to have an option to register an event-handler on WebView/WebEngine for any HTML text input element got/lost focus, so that I could show/hide on-screen-keyboard.
Even though I searched the Internet, I did not find this kind of feature.

My questions:

Does JavaFX / WebView provides any support for these cases?

If you were to tackle this problem, what would be your approach to that?

My solution so far:

I have a small button (at one corner of the screen) that allows user to show/hide on-screen-keyboard. Since they have to do that manually, it is quite annoying. Especially on sites where browsing (consuming information) and text inputs changes frequently.


Solution

  • It would be nice to have an option to register an event-handler on WebView/WebEngine for any HTML text input element got/lost focus, so that I could show/hide on-screen-keyboard.

    A potential strategy for doing this:

    1. Start with a jdk8 preview.
    2. Run the application with -Dcom.sun.javafx.isEmbedded=true to enable the virtual keyboard.
    3. Use a webengine.executeScript technique to embed jQuery into the target page.
    4. Bind a jQuery focus handler to the relevant html elements.
    5. In the jQuery focus handler make an Upcall from JavaScript to Java.
    6. Upon receiving the upcall make use of JavaFX's Virtual Keyboard.
    7. As the user enters values into the keyboard, make executeScript calls to set the value of the corresponding html field.

    Some parts will likely be a bit (or totally) flaky, but perhaps other parts may prove useful to you.

    In the future, if WebView is supported on touchscreen platforms on embedded devices, I'm guessing that out of the box it will work well with a virtual keyboard.

    enter image description here