0

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
    );
}
  • 1
    This isn't anti-cheat. This is how first-person shooters garantees that your mouse will not hit the side of the screen, for example. The game evaluates the delta of the mouse, then reset the cursor back. – Yanick Rochon Oct 05 '22 at 17:34
  • So, how can I fix this? – Vaishnav Kanhirathingal Oct 05 '22 at 17:34
  • have you tried using a timer running at 60 FPS to ever slightly move the cursor? For example, if you want to turn an FPS player right X° within Y ms, then you update the mouse position dx every t frame (depending on your in-game mouse setetings, etc.) – Yanick Rochon Oct 05 '22 at 17:37
  • 1
    The code I have written updates the location of the mouse about 60-120 times a second. But, when in game, The game kinda stutters/glitches if that makes sense. As if, The player rotates x degrees and then comes back x degrees within a few frames. Eventually no change in direction the player is facing. – Vaishnav Kanhirathingal Oct 05 '22 at 17:42
  • Can you share the relevant Java code setting mouse location every frame? – Yanick Rochon Oct 05 '22 at 17:47
  • I just added the code. This function gets called after almost every 12ms. – Vaishnav Kanhirathingal Oct 05 '22 at 18:02
  • Please read : https://stackoverflow.com/a/10725039/320700 – Yanick Rochon Oct 05 '22 at 18:06

0 Answers0