Java - call on-screen keyboard

The application I'm working on will work on Windows 7. It will be used to enter some information using the touch screen. I need to have a popup on the screen whenever the user is asked for information. My question is: should I create a keyboard class from scratch or use the built-in on-screen keyboard of Windows 7 and how can I call it in my Java application? thank you

+4
source share
2 answers

I just played with an on-screen keyboard and saw that it was easy. You just need to call it using Runtime.exec() or ProcessBuilder . Then, if your application has lost focus, return it to the application, while the active element should be the current editable element (text field, text area, etc.). Now, when the user enters the virtual keyboard, the characters are written to your application.

EDIT

There are some difficulties with running osk.exe from java. This throws an 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 through the shell ( cmd ):

Runtime.getRuntime().exec("cmd /c C:\\Windows\\System32\\osk.exe");

This line works great on my car.

+9
source

I encountered the same problem, in addition, I am running a 32-bit application on 64-bit Win7. (I actually use Java-based Matlab) I used the java command Runtime.getRuntime().exec(....) and Matlab system(....) . The behavior was the same: the on-screen keyboard could not be started. I could not find any working solution on Google, so I tried to collect two ideas and update the answer above:

My solution was to explicitly run the 64-bit cmd from the sysnative folder of the re-directive (which is not possible for osk.exe, this leads to an error not found or permissions)

Runtime.getRuntime().exec('C:\windows\sysnative\cmd /c C:\Windows\system32\osk.exe');

Hope this helps.

+3
source

Source: https://habr.com/ru/post/1396443/


All Articles