4

I'm having problems with the java robot, I'm using it to make a pixel bot for a game. when i use the robot to click nothing happens, i have heard that there are more problems with people can't click certain apps. But i couldn't find any solutions for this. i ahve also read about perhaps tracking mouse movement. but that seems weird to me since the key pressing also doesn't work. The game i try to click is probably c++ and DirectX. Im 100% sure my code works since i can move deskopt icons with it and do alooot more stuff. So, is there any way to fix this? or do i need to use an other language? Thanks!

jeroen.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
jeroen
  • 41
  • 2
  • 4

2 Answers2

2

Typical mistakes when working with Robot is that Robot requires absolute screen coordinates. Sometimes people (including myself) get the relative coordinate of button relatively to its window and try to click it with Robot. Make sure that you are able to find the absolute coordinate of screen element you are trying to click.

To be sure that Robot works find coordinate of some desktop icon, e.g. put some icon just near the top-left corner of the screen and click point 20x20. You will see the effect.

Unfortunately you have not provided your code, so I cannot give you better answer.

AlexR
  • 114,158
  • 16
  • 130
  • 208
  • I tryed the idea you gave me with the icon in the top corner, i is just a simple click and drag scipt, And it works fine for me... Also when playing the game, you can just have the screen selected, and press the f1-9 key to use items. when i select the screen and use awtrobot, it doesn't do anything. i also used the robot to make a screenshot where the mouse would click, and that screenshot matches the location where i try to click, i could provide my whole scrpit if you like? – jeroen Nov 10 '11 at 12:55
  • Sorry for delay. I do not have code available right now but I used Robot in past and it worked fine for me. I do not really understand what did not work for you. You can do click, drug mouse, so what does not work? – AlexR Nov 10 '11 at 15:30
  • i will post my code later, I can use all the options from robot on normal desktop, and some more things like paint, en chrome. but there is 1 game, named flyff (wich is an c++ and directx game) where when i try to click or use robot presses it just doesn't work. and i don't know if the game has a way to either block java robot. or that it is written in java and the game is c++. And now my question is: If the game has a way to detect robot, what can i do so it won't detect it. and if it is a problem with java code on c++ how can i fix that? – jeroen Nov 11 '11 at 08:25
  • And also sorry for my late reply – jeroen Nov 11 '11 at 08:25
0

Try this

 public class Main {

    private Robot robot = new Robot();

    public Main() throws AWTException, IOException {
        robotMouseClick(600, 600);
}

    private void robotMouseClick(int x, int y) {
        robot.mouseMove(x, y);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws AWTException, IOException {
        new Main();


      }
}

this worked for me

As far as bot goes u cant really do anything special to any process outside JVM.

nkvnkv
  • 914
  • 2
  • 12
  • 25