Java mouse click

Small code snippet for simulating mouse clicks with java/groovy. Sometimes we need to click hundred times on button next or something similar. This code can be used for this purpose.
In next posts I'll put more advanced version with precise mouse click on coordinates and adding some customization.

Explanation

Code is simulating left mouse click 10 times(press and release of 0.5 sec). If you want to change number of iterations then you should change this line:

for (number in 1..10) {

Code

import java.awt.Robot;
import java.awt.event.KeyEvent;

Robot r = new Robot();
for (number in 1..10) {
   r.mousePress(KeyEvent.BUTTON1_MASK);
   r.delay(500);
   r.mouseRelease(KeyEvent.BUTTON1_MASK);
}