I think is a little bit late but I managed to open and close the virtual keyboard (TabTip.exe) using cmd as you do and JNA (Java Native Access) library:
To open the keyboard:
// Java
String command = "cmd /c \"C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\TabTip.exe\"";
Process = Runtime.getRuntime().exec(command);
process.waitFor();
process.destroy();
// Kotlin
val command = "cmd /c \"C:\\Program Files\\Common Files\\Microsoft Shared\\ink\\TabTip.exe\""
val process = Runtime.getRuntime().exec(command)
process.waitFor()
process.destroy()
To close it:
//Java
String KEYBOARD_CLASS_NAME = "IPTIP_Main_Window";
int WM_SYS_COMMAND = 0x0112;
WinDef.WPARAM SC_CLOSE = WinDef.WPARAM(0xF060);
WinDef.HWND handle = User32.INSTANCE.FindWindow(KEYBOARD_CLASS_NAME, "");
if (handle != null) {
User32.INSTANCE.SendMessage(handle, WM_SYS_COMMAND, SC_CLOSE, WinDef.LPARAM(0));
}
//Kotlin
val KEYBOARD_CLASS_NAME = "IPTIP_Main_Window"
val WM_SYS_COMMAND = 0x0112
val SC_CLOSE = WinDef.WPARAM(0xF060)
val handle = User32.INSTANCE.FindWindow(KEYBOARD_CLASS_NAME, "")
if (handle != null) {
User32.INSTANCE.SendMessage(handle, WM_SYS_COMMAND, SC_CLOSE, WinDef.LPARAM(0))
}
Closing the process or killing it from cmd was not working for me so I had to do it in the native way. I hope this works for you too.