我正在构建一个java机器人,在浏览器中搜索关键字之后,鼠标将直接移动到此关键字的这个实例(突出显示)。
我的问题是我不知道位置(x,y)提前我不能使用mouseMove(x,y)。
在此先感谢您的帮助。
I am building a java robot that after a search of a keyword in a browser the mouse will move directly to this instance of this keyword (which is highlighted).
My problem is a I do not know the position (x,y) in advance I cannot use mouseMove(x,y).
最满意答案
假设您不想在Java中从头开始重写浏览器,唯一的方法是使用Robot.createScreenCapture()创建BufferedImage,然后迭代图像的像素以找到突出显示颜色。
问题是浏览器窗口中的其他内容可能是那种颜色,在这种情况下,您必须更聪明才能到达正确的位置。
无耻的自我推销:前一段时间我创建了一个完全相同的程序,以便自动点击Pandora上的“我仍在听”按钮。 Pandora后来改变了按钮的外观,因此它不再起作用,但是如果你想查看代码仍然可用: http : //staticvoidgames.com/games/StillListening
编辑:这也假设高亮颜色始终相同。 你可能想在潜入之前检查一下这个假设。
The only way to do this, assuming you don't want to rewrite a browser from scratch in Java, is to use Robot.createScreenCapture() to create a BufferedImage, then iterate over the pixels of the image to find the highlight color.
The problem is that other things in the browser window might be that color, in which case you'll have to be more clever to go to the correct place.
Shameless self-promotion: A while ago I created a program that did exactly that, in order to automatically click the "I'm Still Listening" button on Pandora. Pandora has since changed the look of their button so it doesn't work anymore, but the code is still available if you want to check it out: http://staticvoidgames.com/games/StillListening
Edit: This also assumes that the highlight color is always the same. You might want to check that assumption before diving in.
更多推荐
发布评论