问题
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.
回答1:
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:
- Start with a jdk8 preview.
- Run the application with
-Dcom.sun.javafx.isEmbedded=true
to enable the virtual keyboard. - Use a webengine.executeScript technique to embed jQuery into the target page.
- Bind a jQuery focus handler to the relevant html elements.
- In the jQuery focus handler make an Upcall from JavaScript to Java.
- Upon receiving the upcall make use of JavaFX's Virtual Keyboard.
- 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.
来源:https://stackoverflow.com/questions/12704457/javafx-webview-webengine-show-on-screen-keyboard-automatically-for-each-text-i