I would like to write some Java code that will make the mouse "click" somewhere within a 25 by 50 pixel region on the screen. Additionally, I would like the majority of this "clicking" to occur nearer the center of that region (and less around the outside edges of the region). This will approximate the way an actual user might click in the same region.
I am trying to use the nextGaussian method to accomplish this, but I have run into a few snags. One of my criteria is that I don't EVER want to click OUTSIDE the borders (or even ON the borders) of this region and since it is a "standard distribution", eventually nextGaussian will generate numbers that are outside my acceptable range.
I feel like I am close to understanding how this works, but lack of experience is making it slow going. Any suggestions would be appreciated.
Here is what I have so far. I have tinkered with it a bit, but this is the base code...
Robot robot = null;
int xOff = 908;
int yOff = 652;
int w = 25;
int h = 50;
int xCenter = w / 2;
int yCenter = h / 2;
int xTemp;
int yTemp;
int sdX;
int sdY;
Random r = new Random();
for (int idx = 1; idx <= 100; ++idx){
sdX = (int)Math.round(r.nextGaussian() * xCenter + xCenter);
sdY = (int)Math.round(r.nextGaussian() * xCenter + yCenter);
xTemp = sdX + xOff;
yTemp = sdY + yOff;
try {
robot = new Robot();
robot.mouseMove( xTemp, yTemp);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(1000);
} catch (Exception e) {
System.err.println(e.getMessage());
e.printStackTrace();
}