最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Simulating keypress in java running in linux to change keyboard layout - Stack Overflow

programmeradmin1浏览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.

发布评论

评论列表(0)

  1. 暂无评论