Forum Stats

  • 3,769,500 Users
  • 2,252,970 Discussions
  • 7,875,060 Comments

Discussions

Invalid key code

4066777
4066777 Member Posts: 2
edited Aug 19, 2019 3:29AM in Java User Groups Discussions

很简单的一个程序,Windows10系统在德语环境下启动如下程序,总是报错:

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:354)

at testRobot.Main7.main(Main7.java:21)

代码如下;

import java.awt.AWTException;

import java.awt.Robot;

import java.awt.event.KeyEvent;

public class Main7 {

public static void main(String[] args) throws AWTException {

Robot robot = new Robot();

robot.setAutoDelay(300);

robot.delay(5000);

robot.keyPress(KeyEvent.VK_MINUS);

robot.keyRelease(KeyEvent.VK_MINUS);

robot.keyPress(KeyEvent.VK_OPEN_BRACKET );

robot.keyRelease(KeyEvent.VK_OPEN_BRACKET );

robot.keyPress(KeyEvent.VK_SEMICOLON);

robot.keyRelease(KeyEvent.VK_SEMICOLON );

robot.keyPress(KeyEvent.VK_QUOTE);

robot.keyRelease(KeyEvent.VK_QUOTE );

}

}

有没有什么办法能够解决,备注(上面四个键值代表德语的ßüöä)