I want to move the mouse cursor to a specific location and press SHIFT + right-click. I can move the mouse to a location, but I cannot simulate a mouse click.
Robot r = new Robot(); r.mouseMove(x1,y1);
What should I do to simulate the expected mouse click?
I think you only need a little extra information to complete Robot successfully, try
r.keyPress(KeyEvent.VK_SHIFT); r.mousePress(KeyEvent.BUTTON3_MASK); r.mouseRelease(KeyEvent.BUTTON3_MASK); r.keyRelease(KeyEvent.VK_SHIFT);
this should do the trick:
r.mousePress(InputEvent.BUTTON3_MASK); r.mouseRelease(InputEvent.BUTTON3_MASK);
It is important not to forget to press and release it, as these are two different events.
robot class :
robot
class
r.keyPress(KeyEvent.VK_SHIFT); //hold down shift r.mousePress(InputEvent.BUTTON3_MASK); //perform a right click r.mouseRelease(InputEvent.BUTTON3_MASK); //release right click r.keyRelease(KeyEvent.VK_SHIFT); //release shift
InputEvent KeyEvent java.awt.event.
InputEvent
KeyEvent
java.awt.event