[102] | 1 | /*
|
---|
| 2 | * Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
| 3 | * License BSDLike http://rickvanderzwet.nl/LICENSE
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /* Based after http://ironbark.bendigo.latrobe.edu.au/~mary/DS/lectures/tutorials/ACSWorkshop98.html */
|
---|
| 7 | package nl.rickvanderzwet.farmville;
|
---|
| 8 |
|
---|
| 9 | import java.awt.AWTException;
|
---|
| 10 | import java.awt.Robot;
|
---|
| 11 | import java.awt.event.InputEvent;
|
---|
| 12 | import java.util.Random;
|
---|
| 13 | import java.io.IOException;
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 |
|
---|
| 17 | public class MouseClicker {
|
---|
| 18 | /**
|
---|
| 19 | *
|
---|
| 20 | */
|
---|
| 21 | private static final long serialVersionUID = -9024149555631644329L;
|
---|
| 22 | public enum Direction {
|
---|
| 23 | UP, DOWN, LEFT, RIGHT
|
---|
| 24 | }
|
---|
| 25 |
|
---|
| 26 | private static Robot bot = null;
|
---|
| 27 | private static Random randomGenerator = null;
|
---|
| 28 |
|
---|
| 29 | private static void pressMouse() throws InterruptedException {
|
---|
| 30 | bot.mousePress(InputEvent.BUTTON1_MASK);
|
---|
| 31 | bot.mouseRelease(InputEvent.BUTTON1_MASK);
|
---|
| 32 |
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | /**
|
---|
| 36 | * @param args
|
---|
| 37 | * @return
|
---|
| 38 | * @throws InterruptedException
|
---|
| 39 | * @throws IOException
|
---|
| 40 | */
|
---|
| 41 |
|
---|
| 42 | public static void main(String[] args) throws InterruptedException, IOException {
|
---|
| 43 |
|
---|
| 44 | try {
|
---|
| 45 | //bot.mouseMove(100, 100);
|
---|
| 46 | bot = new Robot();
|
---|
| 47 | randomGenerator = new Random();
|
---|
| 48 |
|
---|
| 49 | // Allow time to focus Firefox window
|
---|
| 50 | Thread.sleep(3000);
|
---|
| 51 |
|
---|
| 52 | for (int i = 0; i < 400; i++) {
|
---|
| 53 | pressMouse();
|
---|
| 54 | // Constant values are tricky, computers can only do that
|
---|
| 55 | Thread.sleep(200 + randomGenerator.nextInt(25));
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | } catch (AWTException e) {
|
---|
| 59 | // TODO Auto-generated catch block
|
---|
| 60 | e.printStackTrace();
|
---|
| 61 | }
|
---|
| 62 |
|
---|
| 63 | // TODO Auto-generated method stub
|
---|
| 64 |
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 |
|
---|
| 68 |
|
---|
| 69 | }
|
---|