gpt4 book ai didi

Java Robot 类鼠标移动到特定像素的位置(鼠标单击颜色)

转载 作者:行者123 更新时间:2023-11-30 09:24:29 25 4
gpt4 key购买 nike

如何找到坐标变化的颜色,识别后需要点击的位置。

程序的目的是完成游戏中的任务,需要点击并不总是在同一位置的不同颜色。

代码当前在执行程序 5 秒后获取鼠标坐标的颜色


public class RobotColorClick 
{

public RobotColorClick () throws AWTException, IOException, InterruptedException
{
Robot robot = new Robot();

//Delay 5 seconds
robot.delay(5000);

//Gets color (value of red,green,blue) from the mouse position after 5 seconds
Color color = robot.getPixelColor( MouseInfo.getPointerInfo().getLocation().x
, MouseInfo.getPointerInfo().getLocation().y);

//Delay 3 seconds
robot.delay(3000);

//Mouse moves to X and Y then right click
//Problem! How to set X and Y to position color coordinates, position will change
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);

}


public static void main(String[] args) throws AWTException, IOException,
InterruptedException
{
new RobotColorClick ();
}
}

最佳答案

如果颜色继续路径而不是跳跃 read Kevin Mangold answer否则,如果它只是出现在任何地方的颜色,我认为你有 2 个选项(如果背景颜色不变):

第一个:您可以拍摄屏幕截图并对其进行迭代并获取任何出现的颜色(或特定颜色)的坐标,然后使用机器人库 this may help 按下它and this for taking screenshots

第二个:如果您不想截取屏幕截图,您可以使用机器人库通过 2 个嵌套 for 循环遍历所有屏幕像素来遍历屏幕 THis may help

如果背景图像不是固定的,您可以截取屏幕截图并将其与之前的进行比较,使用 robot lib 按下差异。

Extra 我之前在某处读过,当使用机器人库按下按钮时,最好这样做robot.mousePress(InputEvent.BUTTON1_MASK);
机器人延迟(1);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
而不是这个

robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);

额外的东西你可以从你的软件中读取游戏内存并获得你想要的颜色坐标

关于Java Robot 类鼠标移动到特定像素的位置(鼠标单击颜色),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15687313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com