I am working on a project similiar to cloud gaming. I am also currently using java.awt.Robot
to emulate mouse movements. But, the problem is that it does not work inside most games. While I was attempting to move my mouse inside the game, I also captured its locations. Here's the data -
While inside the game -
mouse: x = 959 y = 540
mouse: x = 959 y = 540
mouse: x = 959 y = 540
mouse: x = 959 y = 540
mouse: x = 960 y = 539
mouse: x = 959 y = 540
mouse: x = 960 y = 539
mouse: x = 960 y = 540
mouse: x = 959 y = 540
mouse: x = 959 y = 539
mouse: x = 959 y = 539
mouse: x = 959 y = 539
mouse: x = 960 y = 540
mouse: x = 960 y = 540
mouse: x = 959 y = 540
mouse: x = 959 y = 540
mouse: x = 960 y = 539
mouse: x = 959 y = 540
mouse: x = 959 y = 540
mouse: x = 959 y = 540
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 959 y = 540
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 960 y = 539
mouse: x = 947 y = 534
mouse: x = 924 y = 540
While outside the game -
mouse: x = 1537 y = 229
mouse: x = 1537 y = 229
mouse: x = 1537 y = 229
mouse: x = 1475 y = 238
mouse: x = 1119 y = 465
mouse: x = 627 y = 943
mouse: x = 480 y = 1056
mouse: x = 575 y = 939
mouse: x = 827 y = 263
mouse: x = 616 y = 776
mouse: x = 213 y = 1005
mouse: x = 1679 y = 48
mouse: x = 1679 y = 48
mouse: x = 1679 y = 48
mouse: x = 1679 y = 48
mouse: x = 1679 y = 48
mouse: x = 1425 y = 238
mouse: x = 991 y = 443
These locations were recorded after every second and the issue isn't there while outside the game. If you look closely, The mouse is kinda forced to stay at the center of the screen while in-game. 960, 540
for the screen resolution of 1920, 1080
. This might not be an anti-cheat system issue because I also tried this for shadow of the tomb raider and kinda the same issue there.
Ideas tried from other Stackoverflow questions -
- Somebody suggested changing the game to windowed instead of full-screen, that didn't work.
- Another suggestion was to run the IDE in administrator mode, didn't work.
The main aim of emulating mouse is so that I can control my games as if I was controlling the mouse myself. I was able to get everything working from mouse clicks to key presses to long presses. This is the last step.
code added -
void animateMouse(int dx, int dy) {
robot.mouseMove(
MouseInfo.getPointerInfo().getLocation().x + dx,
MouseInfo.getPointerInfo().getLocation().y + dy
);
}