Reputation: 3269
I am trying to simulate user input in Minecraft Java Edition on Windows running in background. Specifically, I want to simulate holding left mouse button.
In order to simplify it, I set rawMouseInput:false
in options.txt
.
For mouse input the issue is that after receiving WM_LBUTTONDOWN
Minecraft behaves as if WM_LBUTTONUP
immediately followed although I can see in the debugger that it is not the case. As a result actions like mining a block start but are immediately interrupted.
Now I did some investigation, and it seems that Minecraft is using LWJGL 3 Java library, which in turn uses GLFW C library to handle user input.
I cloned latest GLFW and built a simple boing
example. However, I can not reproduce the same issue with that example: boing
appears to correctly treat WM_LBUTTONDOWN
as the beginning of the action, and does not stop the action until I send WM_LBUTTONUP
.
Is there something special Minecraft does for input that causes such behavior?
How do I simulate holding left mouse button in Minecraft running in background?
Upvotes: 1
Views: 428
Reputation: 1
It seems that you've overthought this a bit too much. Java has a built-in keyboard and mouse simulator, which, as far as I've seen, works fine.
java.awt.Robot robot = new Robot();
robot.mousePress(MouseEvent.<your_button_here>);
---<wait however long you want>---
robot.mouseRelease(MouseEvent.<your_button_here>);
Sorry if this appears off-topic, but it does avoid a whole host of problems...
Upvotes: 0