Java的AWT机器人仍然在Windows着preSS非数字键盘箭头? [英] Java awt Robot still cant press non-numpad arrows on windows?
问题描述
此错误是相识多年,但目前仍处于美元的Java p $ psent 1.7.0_25
这我使用的是Windows 8的下面的结果是版本一样的,不管阉羊的,我有NumLock键开启或不:
This bug is known for years, yet is is still present in Java 1.7.0_25
version which I'm using on Windows 8. The following result are same regardless of wether i have numlock turned on or not:
Robot bot = new Robot();
bot.keyPress(KeyEvent.VK_UP); //this in documentation is non-numpad up arrow key
bot.keyRelease(KeyEvent.VK_UP); //pressed the numpad up arrow key
//folowing line is line #43
bot.keyPress(KeyEvent.VK_KP_UP); //this in documentation is numpad up arrow key
bot.keyRelease(KeyEvent.VK_KP_UP); //causes folowing exception:
Exception in thread "main" java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Robot.java:358)
at test.RobotArrow.main(RobotArrow.java:43)
我知道这个问题已经被问<一个href=\"http://stackoverflow.com/questions/12565510/java-key$p$pss-arrow-keys-triggers-numpad-keys\">here但在一年前,那么有没有什么进展?我不能谷歌任何东西,甚至有一个 ofiicial bug报告
I know this question was already asked here but over a year ago, so is there any progress? I cant google anything, there is even an ofiicial bug report
那么,有没有一个finnaly溶液或不?
So, is there finnaly a solution or not?
推荐答案
// $ P $ WINDOWS干燥综合征+左箭头
//PRESS WINDOWS + ARROW LEFT
Robot divideWindow = new Robot();
divideWindow.keyPress(KeyEvent.VK_WINDOWS);
divideWindow.delay(100);
divideWindow.keyPress(KeyEvent.VK_LEFT);
divideWindow.delay(100);
divideWindow.keyRelease(KeyEvent.VK_LEFT);
divideWindow.delay(100);
divideWindow.keyRelease(KeyEvent.VK_WINDOWS);
对我的作品罚款:)
Works fine for me :)
这篇关于Java的AWT机器人仍然在Windows着preSS非数字键盘箭头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!