Problems with java Robot. mouse click does not work

I have problems with a java robot, I use it to create a pixel bot for the game. when I use a robot to do nothing, I heard that there are more problems with people who cannot click certain applications. But I could not find solutions for this. I also read about possibly tracking mouse movement. but this seems odd to me, as keystroke also doesn't work. The game I'm trying to click is probably C ++ and DirectX. Im 100% sure my code is working, as I can move deskopt icons with it and do alooot more things. So, is there a way to fix this? or do i need to use another language? Thanks!

Jeroen.

+4
source share
2 answers

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

To make sure that the robots are working, find the coordinates of a desktop icon, for example. place the icon next to the upper left corner of the screen and press the 20x20 button. You will see the effect.

Unfortunately, you did not provide your code, so I cannot give you a better answer.

+1
source

try it

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(); } } 

it worked for me

As for the bot, it really does something special for any process outside the JVM.

0
source

Source: https://habr.com/ru/post/1380567/


All Articles