问题
I'm working on a remoting app.(mouse - keyboard) I just showing fastly my issue...
It's working for 'A' or some basic characters.
case "a":
robot.keyPress(KeyEvent.VK_A);
But I did'nt make '@' character. My way is look like this.
case "@":
robot.keyPress(KeyEvent.VK_ALT_GRAPH);
robot.keyPress(KeyEvent.VK_Q);
robot.keyRelease(KeyEvent.VK_ALT_GRAPH);
I see the exception when I use VK_ALT_GRAPH;
Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: Invalid key code
at sun.awt.windows.WRobotPeer.keyPress(Native Method)
at java.awt.Robot.keyPress(Unknown Source)
Is that a bug? How can I press '@' char? Also like this, I cant do these ; $ , # , ? , [ , ] , {, } , ' , * ...
回答1:
I know that this is very old, but nobody gave a correct answer and after practicing I went with the solution.
That is my keyboard:
and for press @ or # you must to do it:
bot.keyPress(VK_CONTROL);
bot.keyPress(VK_ALT);
bot.keyPress(VK_3);
bot.keyRelease(VK_CONTROL);
bot.keyRelease(VK_ALT);
bot.keyRelease(VK_3);
来源:https://stackoverflow.com/questions/22919591/robot-keypress-doesnt-work-for-vk-alt-graph-invalid-key-code