java 无法让机器人类右键单击
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14709096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot get Robot class to right click
提问by Simulant
I am trying to get the Robot class to right click on a image on the screen so that I can save it. The problem is though that I cannot seem to get the Robot to successfully simulate a right click. Here is some sample code of what I am doing.
我试图让 Robot 类在屏幕上的图像上单击鼠标右键,以便我可以保存它。问题是我似乎无法让机器人成功模拟右键单击。这是我正在做的一些示例代码。
It seems that BUTTON2_DOWN_MASK is the mask for the scroll wheel. Whenever I execute this code it first just regularly clicks at the location but then the scroll wheel super fast move circle pops up and tells me I can now scroll at light speed, but I wanted a right click..
似乎 BUTTON2_DOWN_MASK 是滚轮的掩码。每当我执行此代码时,它首先只是定期点击该位置,然后弹出滚轮超快速移动圆圈并告诉我现在可以以光速滚动,但我想要右键单击..
CODE:
代码:
// This is the function I use to simulate a full click at location x,y on the screen
// Rob is my Robot
public void click(int x, int y, int mask)
{
rob.mouseMove(x, y);
sleepy(1000);
rob.mousePress(mask);
rob.mouseRelease(mask);
}
// This is the few lines of code that call this function
// sleepy just calls the Thread.sleep function.
sleepy(1000); // Wait one second
click(705, 390, InputEvent.BUTTON1_DOWN_MASK);
sleepy(1000);
click(705, 390, InputEvent.BUTTON2_DOWN_MASK);
sleepy(1000);