open the Windows virtual keyboard in a Java program

后端 未结 3 1742
醉话见心
醉话见心 2020-12-20 10:02

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?

相关标签:
3条回答
  • 2020-12-20 10:15

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

    0 讨论(0)
  • 2020-12-20 10:27

    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.
    0 讨论(0)
  • 2020-12-20 10:30

    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.

    0 讨论(0)
提交回复
热议问题