在游戏中移动鼠标的正确方法是什么?
问题描述:
我要编为的Minecraft一个机器人,可以自动收集物品。但我在游戏中移动鼠标时遇到问题。这个动作很奇怪......即使我只在y坐标上加1,它也会在x和y坐标上跳跃。 movment在每个3D游戏中都像这样,不仅在我的世界里。在游戏中移动鼠标的正确方法是什么?
对于运动我用的是integreated robot class。
这里是剪断我使用的鼠标移动:
public static void main(String[] args) {
try {
Robot bot = new Robot();
Point mouseposition = MouseInfo.getPointerInfo().getLocation();
int x = mouseposition.x;
int y = mouseposition.y;
//used to switch to the game window
bot.delay(5000);
y += 1;
bot.mouseMove(x, y);
} catch (AWTException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我用这个代码预期是,该课程只是移动一个像素下来。如果我在桌面上,光标移动正常!
系统:
- 操作系统:Windows 8.1
- 弓:AMD64
- javaversion:1.7.0_67
- IDE:Eclipse的月神
答
你'重新捕捉环鼠标位置切换到游戏窗口之前,所以当你加1,y坐标,你实际上增加1到鼠标是你感动它切换到游戏窗口之前。将延迟放在Point mouseposition = MouseInfo.getPointerInfo().getLocation();
行之前。
+0
*捂脸*非常感谢你......你是我的权利我之前得到了COORDS是在游戏中! Dident发现错误 – Gerret 2014-10-10 15:25:03
是什么bot.mouseMove(X,Y)呢?你有这个代码吗? – david99world 2014-10-10 15:09:36
@ david99world这是在集成[机器人类(http://docs.oracle.com/javase/7/docs/api/java/awt/Robot.html)为Java。它应该将鼠标移动到屏幕的x和y坐标上。 – Gerret 2014-10-10 15:10:45