Paul Lutus said:
For your answer, post your commmand-line (non-GUI) application that provides
the mouse's position on the screen.
I wrote a program (with no interface) that is able to click anywhere on the
screen repeatedly thus serving the needs I expressed in the previous thread
i.e. to click the OK button of the message that pops up every minute in the
game (actually my 3 year old kid plays the game and i'm doing this for him
and for myself (learning java)). The location (x,y) and the time interval
(d) between each click is supplied thru command line arguments. Here is the
program
import java.awt.* ;
import java.util.* ;
public final class ClickMouse extends TimerTask {
public static int x, y, d ;
public static void main(String[] args) {
TimerTask clikMouse = new ClickMouse();
Timer t = new Timer();
x = Integer.parseInt(args[0]) ;
y = Integer.parseInt(args[1]) ;
d = Integer.parseInt(args[2]) ;
t.schedule(clikMouse,1000,d*1000);
}
public void run() {
try {
Robot bot = new Robot();
bot.mouseMove(x,y);
bot.mousePress(java.awt.event.InputEvent.BUTTON1_MASK );
bot.mouseRelease(java.awt.event.InputEvent.BUTTON1_MASK);
}
catch (Exception e)
{
System.out.println("Exception occured :" + e.getMessage());
}
}
Now ideally I would like the program to end when my kid is finished with the
game so that the mouse is released and he can play any other game he wants.
The best way that comes to my mind (any other ideas are welcome but I just
dont want to make him click the mouse or press any key) is that when the
mouse is moved more than certain distance from the point (x,y) the program
should end i.e to release the mouse just move it far enough. For this my
program needs to determine the mouse position every time before clicking at
x,y ( I could put a flag to make sure it doesnt quit the first time it
clicks etc). So here is how things will go
1. My son starts the (keyboard based) game and this java app at the same
time
2. Every time the message box of the game pops up it will be closed by my
program within 2 seconds ( the position of the OK button is always the same
so my app would start always with the same arguments e.g javaw ClickMouse
"400" "500" "2"
I've checked this functionality and it works, now only the last part. When
he moves the mouse (which he will naturally) I want the program to end thus
releasing the mouse. for this, the app needs to know the absolute position
of the mouse so that it can compare it with x,y or just the relative
distance from x,y.