简体   繁体   中英

Java Robot won't work when Chrome is in focus

I'm having a weird issue. I'm trying to do some clicking with the robot class in java. All works fine except for when chrome is in focus. This is my method:

public static void click(int X, int Y) {
    PointerInfo info = MouseInfo.getPointerInfo();
    Point p = info.getLocation();
  //robo.mouseRelease(InputEvent.BUTTON1_MASK);
    robo.mouseMove(X, Y);
    robo.mousePress(InputEvent.BUTTON1_MASK);
    robo.mouseRelease(InputEvent.BUTTON1_MASK);
    System.out.println("Clicked at X: "+X+" Y: "+Y);
  //robo.mouseMove((int) p.getX(), (int) p.getY());
}

It just won't move or click when Chrome is focused. If I switch to notepad for example, it works.

Does Chrome have some kind of anti-macro stuff going on?

Thanks, have a nice day!

Well, I suspected that Windows was the issue from the very get go since after the last reinstall i had some issues with it. I had the same Windows from my hidden partition for 4 years now,reinstalling it every 4-6 months. Last week, when I reinstalled it, i had some permission issues, out of nowhere. I couldn't delete, move, copy, access stuff,etc. Had to play with ownership and stuff. Dunno where this came from, I didn't allow any windows updates thru. Unless it updated my hidden partition setup files, which I don't know if it is possible.

So last night I figured hey, lets activate the hidden Administrator account and see if the issue is still there. Well, it isn't. And now I went back to my normal account and all is fine now.

Short version: Enabled the hidden Administrator account on Windows 7, the issue is now gone on both accounts. Have a good day and thanks for your help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM