The application I am working on will run on Windows 7. It will be used to input some information via touchscreen. I need to have an on-screen keyboard popup whenever user is prompted for information. My question is, should I create a keyboard class from scratch or should I use the Windows 7 built-in on-screen keyboard and how would I invoke it in my Java application? Thank you
I have just played with on-screen keyboard and saw that it is easy. You just have to invoke it using either Runtime.exec()
or ProcessBuilder
. Then if your application lost focus take it back to the application, while the active element must be the current editable element (text field, text area etc). Now when user is typing on the virtual keyboard the characters are being written to your application.
There are some difficulties to execute osk.exe from java. It throws IOException:
java.io.IOException: Cannot run program "C:\Windows\System32\osk.exe": CreateProcess error=740, The requested operation requires elevation
The trick is to run the command via command shell (cmd
):
Runtime.getRuntime().exec("cmd /c C:\\Windows\\System32\\osk.exe");
This line works fine on my machine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With