Robot mouseMove helppp (IllegalThreadStateException)

When I set my Robot to “setAutoWaitForIdle(true)” (so it cues the next event after the Robot stops), I get an “IllegalThreadStateException”…

What’s wrong ???

`
Robot mouseBot;
boolean RobotMove=true;

public void startMouseRobot(){
	try{mouseBot=new Robot();}
	catch(Exception e){}
	mouseBot.setAutoWaitForIdle(true);
	}

public void robotResetMouse(){
	//set RobotMove to true
	//move cursor
	//set RobotMove to false
	RobotMove=true;
	mouseBot.mouseMove(screenSize.width/2, screenSize.height/2);
	RobotMove=false;
	}

`

(Im using the boolean RobotMove to determine the difference between a user mouse move and a robot mouse move. Is there another way to do this?)

You can’t wait for idle from the EDT. Because it waits for the EDT to idle.

I dont get it :’(

If you call the Robot.mouseMove from the EDT (EventDispatcherThread), when setAutoWaitForIdle is true, it will call Robot.waitForIdle() automaticly.

Robot.waitForIdle() may not be called from the EDT, as it waits for the very same EDT to finish. (It cannot wait for itself to finish).

The sun-engineers prevented that that call would be hanging for ever, instead they throw an Exception to warn you.

Then how can I queue the next action following Robot.mouseMove()? Like after the mouseMove thread is finished?

Just run all calls to Robot from your own thread, or create one, especially for it.

Or disable waitForIdle and roll your own code to handle the situation correctly.