Question

We are making an emulator for disabled persons. There is a desktop area in this app which we are testing at the moment. How can I programmatically generate 1 mouse click and immediately after it 1 keyboard click? Time between clicks is 100 ms.

EDIT

This is the code from your suggestions.

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);
              }
            });
    }
}

There are 5 errors which are shown in the snapshot.

Was it helpful?

Solution

Take a look at the Robot class, which can be used to programmatically generate mouse clicks and keyboard strokes. You could use this in conjunction with the Swing Timer class to periodically generate these events; e.g.

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);
  }
});

OTHER TIPS

Look at the Robot class.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top