0

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
  • What code have you written and tried so far?
    – Woot4Moo
    Commented Feb 9, 2011 at 17:41

4 Answers 4

4

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

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

1
  • How to make the OSK with Java (not just execute OSK, because it has some dangerous keys)
    – user285594
    Commented Dec 15, 2016 at 19:58
1

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.
1
  • Anyone know how to open the other virtual keyboard in Windows, not osk? The one for tablets?
    – M. H.
    Commented Aug 4, 2017 at 4:02
0

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

1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review Commented Mar 11, 2022 at 17:06

Not the answer you're looking for? Browse other questions tagged or ask your own question.