0

I'm trying to create a game bot using the Robot class. I have tried the following code to perform a right click of the mouse:

robot.mousePress(InputEvent.BUTTON3_MASK);
robot.mouseRelease(InputEvent.BUTTON3_MASK);

And it worked.

I'm testing it on a client side 3d online game.

Pressing the key "1" should perform some kind of a movement ingame, and when I tried the following code it didn't worked:

robot.keyPress(KeyEvent.VK_1);
robot.keyRelease(KeyEvent.VK_1);

But it did worked when I used that code while speaking in the chat in game.

It's been tested over and over and I keep getting the same result.

Is it something that I have done wrong?or somehow the game detect that I'm not the one that pressing that key.

1 Answer 1

6

You are probably releasing the key too quickly. Try sleeping for 30~60ms before releasing the key:

robot.keyPress(KeyEvent.VK_1);
try {
    Thread.sleep(50);
} catch(Exception e) {
    e.printStackTrace();
}
robot.keyRelease(KeyEvent.VK_1);
Sign up to request clarification or add additional context in comments.

1 Comment

@ImriPersiado If it fixed your issue, you should be able to accept nneonneo's answer already, I don't believe SO restricts anyone's ability to accept answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.