open the Windows virtual keyboard in a Java program

有些话、适合烂在心里 提交于 2019-11-28 06:50:58

问题


I would like to create an event in a button.

When I click in the button, I would like to open the Windows virtual keyboard.

Can you help me with the code?

Thank you for your collaboration.

Best regards.


回答1:


I think it would be as simple as this: Runtime.getRuntime().exec("osk");




回答2:


You can use getRuntime to execute it:

import java.io.IOException;

public class ShowVirtualKeyboard{

    public static void main(String argv[]) throws IOException {
    String sysroot = System.getenv("SystemRoot");
    Process proc = Runtime.getRuntime().exec(sysroot + "/system32/osk.exe");
}
}

and you can call proc.destroy() to get rid of it.

Regards.




回答3:


This will work: Runtime.getRuntime().exec("cmd /c osk");

cmd /c will launch the process and invoke the UAC if needed.

Advantage:

  • And it would avoid privileges issue.

Disadvantage:

  • Would not be able to turn off by Process instance on java.


来源:https://stackoverflow.com/questions/4948420/open-the-windows-virtual-keyboard-in-a-java-program

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!