4

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.

Radek Červenec
  • 115
  • 2
  • 8

1 Answers1

6

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

jewelsea
  • 150,031
  • 14
  • 366
  • 406
  • Thank you very much for the answer – it has been great source of inspiration!!! And it works! To solve my problem I used only points: 3.- 5. of Your answer. As virtual keyboard I used similar solution to: http://code.google.com/p/fx-onscreen-keyboard/ that utilizes Robot class so I could skip points: 6. and 7. Moreover, all can be implemented with JDK7. I actually did not manage to get JavaFX Virtual Keybord working…. is there any working example of JavaFX VKB or any images of the keyboard – just for my curiosity and to compare solutions? – Radek Červenec Oct 03 '12 at 11:47
  • I haven't used the Virtual Keyboard either. I copied an image of the keyboard displayed by a BeagleBoard ARM computer from of one the [JavaFX issue tracker cases](http://javafx-jira.kenai.com/browse/RT-25266). And I placed the image into the answer. – jewelsea Oct 03 '12 at 15:53
  • Well, my platform is x86. That could be the problem with JavaFx Virtual Keyboard as I don’t know if it is already supported. Anyway, I can live without JavaFx VK as my core problem was how to detect a requirement for a keyboard. And that is solved! You have been very helpful to me. Thanks again! (I would upvote the answer but I am not allowed to do that yet:-) – Radek Červenec Oct 03 '12 at 17:07