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

荒凉一梦 提交于 2019-12-31 02:25:08

问题


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:

  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.



来源:https://stackoverflow.com/questions/12704457/javafx-webview-webengine-show-on-screen-keyboard-automatically-for-each-text-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!