0

I am writing a dictionary program with requires switching keyboard layout.

I have kde set up that ctrl-alt-k switches layout.

I have tried simulating the ctrl-alt-k keypress from the program but this doesn't seem to do anything.

try {
  Robot r = new Robot();
  r.keyPress(KeyEvent.VK_CONTROL);
  r.keyPress(KeyEvent.VK_ALT);
  r.keyPress(KeyEvent.VK_K);
  r.keyRelease(KeyEvent.VK_K);
  r.keyRelease(KeyEvent.VK_CONTROL);
  r.keyRelease(KeyEvent.VK_ALT);
} catch (Exception e) {
e.printStackTrace();
}

Why doesn't this work? I have managed to simulate ctrl-c with similar code but this does nothing.

2
  • Try putting a delay of 200 milliseconds between the press and the release. Commented Apr 3 at 5:15
  • I have already tried that and it still doesn't work. Commented Apr 3 at 14:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.