1

我们正在为残疾人制作模拟器。这个应用程序中有一个桌面区域,我们目前正在测试。如何以编程方式生成 1 次鼠标单击并在单击 1 次键盘后立即生成?点击之间的时间为 100 毫秒。

编辑

这是您的建议中的代码。

import java.awt.Robot;
import java.io.Console;

import javax.swing.Timer;

public class Start {

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Timer timer = new Timer(100, new ActionListener() {
              private final Robot robot = new Robot();

              public void actionPerformed(ActionEvent evt) {
                robot.mousePress(1);
                robot.mouseRelease(1);
                robot.keyPress(KeyEvent.VK_A);
                robot.mouseMove(55, 145);
              }
            });
    }
}

快照中显示了 5 个错误。

4

2 回答 2

4

看看这个Robot类,它可以用来以编程方式生成鼠标点击和键盘敲击。您可以将它与 SwingTimer类结合使用来定期生成这些事件;例如

Timer timer = new Timer(100, new ActionListener() {
  private final Robot robot = new Robot();

  public void actionPerformed(ActionEvent evt) {
    robot.mousePress(1);
    robot.mouseRelease(1);
    robot.keyPress(KeyEvent.VK_A);
  }
});
于 2011-10-20T09:18:44.470 回答
0

看看机器人类

于 2011-10-20T09:19:07.410 回答