Daniel Pereira
Daniel Pereira

Reputation: 453

open the Windows virtual keyboard in a Java program

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.

Upvotes: 0

Views: 9296

Answers (4)

Kevin Meneses Palta
Kevin Meneses Palta

Reputation: 85

Maybe this is a little bit late but if you cannot manage to close the keyboard too, this answer may help you https://stackoverflow.com/a/71410876/12346089

Upvotes: 0

taynguyen
taynguyen

Reputation: 3611

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.

Upvotes: 1

CarlG
CarlG

Reputation: 1666

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

Upvotes: 3

jhurtado
jhurtado

Reputation: 8747

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.

Upvotes: 4

Related Questions