Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - invoke on-screen keyboard

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

like image 330
jadrijan Avatar asked Dec 12 '22 05:12

jadrijan


1 Answers

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.

EDIT

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.

like image 196
AlexR Avatar answered Dec 28 '22 08:12

AlexR