1

I have a simple Java project that uses Robot to simulate a simple mouse movement as shown below.

while(true){
try {
    for(int x=0; x<200; x++){
        r.mouseMove(x, 300);
        Thread.sleep(10);
    }
    Thread.sleep(3000);
} catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
}
}

The code works fine when I run it. The problem is that as soon as I click on this gaming application window, the cursor no longer moves. The whole point of this project is to automate particular mouse movements within a game, but when I click on this game window it appears the Robot class no longer does anything. As soon as I click out of the gaming window, the automated mouse movements continue as normal. Why is the Robot mouse movements not working when I click on this gaming window? Is it a problem with Java Robot? Is there an alternative I can try instead of Robot? Programming automated mouse movements should be possible when this game window is selected since a macro recorder I downloaded is able to simulate mouse movements in the game. Why would the code for this macro recorder be able to move the mouse cursor in the game while the Java code I am writing is not able to move the mouse cursor?

Mark Booth
  • 7,605
  • 2
  • 68
  • 92
user3858843
  • 95
  • 1
  • 13
  • A lot of games have mechanism to prevent this kind of behaviour and it simply may not be possible to implement – MadProgrammer Feb 28 '16 at 23:31
  • Maybe this thread will help: http://stackoverflow.com/questions/19185162/how-to-simulate-a-real-mouse-click-using-java – Sason Ohanian Feb 28 '16 at 23:36
  • Then how is this macro recorder I downloaded capable of moving the game's cursor? – user3858843 Feb 28 '16 at 23:37
  • Can you add the relevant code of your gaming window? Without that code there are dozens of possibilities and you will not get a decent response – Norbert Feb 28 '16 at 23:40
  • @SasonOhanian Thank you, the thread helped. The problem was that I had to run eclipse as an administrator. After doing that mouse movements became possible in the game. – user3858843 Feb 28 '16 at 23:49

1 Answers1

4

Had to run Eclipse as an Admin.

user3858843
  • 95
  • 1
  • 13