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?

5
  • A lot of games have mechanism to prevent this kind of behaviour and it simply may not be possible to implement Commented Feb 28, 2016 at 23:31
  • Maybe this thread will help: stackoverflow.com/questions/19185162/… Commented Feb 28, 2016 at 23:36
  • Then how is this macro recorder I downloaded capable of moving the game's cursor? Commented Feb 28, 2016 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 Commented Feb 28, 2016 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. Commented Feb 28, 2016 at 23:49

1 Answer 1

4

Had to run Eclipse as an Admin.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.