本文整理汇总了Java中java.awt.Robot.mousePress方法的典型用法代码示例。如果您正苦于以下问题:Java Robot.mousePress方法的具体用法?Java Robot.mousePress怎么用?Java Robot.mousePress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Robot
的用法示例。
在下文中一共展示了Robot.mousePress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.awt.Robot; //导入方法依赖的package包/类
private static void test(GraphicsConfiguration gc) throws AWTException {
final Window frame = new Frame(gc);
try {
frame.addMouseWheelListener(e -> {
wheelX = e.getXOnScreen();
wheelY = e.getYOnScreen();
done = true;
});
frame.setSize(300, 300);
frame.setVisible(true);
final Robot robot = new Robot();
robot.setAutoDelay(50);
robot.setAutoWaitForIdle(true);
mouseX = frame.getX() + frame.getWidth() / 2;
mouseY = frame.getY() + frame.getHeight() / 2;
robot.mouseMove(mouseX, mouseY);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseWheel(10);
validate();
} finally {
frame.dispose();
}
}
示例2: performTest
import java.awt.Robot; //导入方法依赖的package包/类
@Override
protected boolean performTest() {
try {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
splitterLoc = sp2.getLocationOnScreen();
Point leftLoc = sp1.getLocationOnScreen();
leftLoc.translate(sp1.getWidth(), 0);
splitterLoc.translate(-(splitterLoc.x - leftLoc.x) / 2, 30);
}
});
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Where is splitter?");
}
// run robot
Robot robot = Util.createRobot();
robot.setAutoDelay(ROBOT_DELAY);
robot.mouseMove(splitterLoc.x, splitterLoc.y);
Util.waitForIdle(robot);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(splitterLoc.x - 50, splitterLoc.y);
Color c = robot.getPixelColor(splitterLoc.x - 50, splitterLoc.y);
System.out.println("Actual: "+c+", (not) expected: "+AWT_VERIFY_COLOR+" at "+(splitterLoc.x - 50)+", "+ splitterLoc.y);
if (!ignoreFail && c.equals(AWT_VERIFY_COLOR)) {
fail("The JSplitPane drag-n-drop image did not pass pixel color check and is overlapped");
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
clickAndBlink(robot, splitterLoc);
return clicked;
}
示例3: test
import java.awt.Robot; //导入方法依赖的package包/类
private static void test(final int mask) throws Exception {
final Robot r = new Robot();
r.setAutoDelay(100);
r.setAutoWaitForIdle(true);
EventQueue.invokeAndWait(MouseModifiersInKeyEvent::createAndShowGUI);
r.waitForIdle();
EventQueue.invokeAndWait(() -> bounds = f.getBounds());
r.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
r.mousePress(mask);
r.keyPress(KeyEvent.VK_A);
r.keyRelease(KeyEvent.VK_A);
EventQueue.invokeAndWait(() -> f.dispose());
r.mouseRelease(mask);
// all extended modifiers should work
if (modifiersEX != mask) {
System.err.println("Expected modifiersEX: " + mask);
System.err.println("Actual modifiersEX: " + modifiersEX);
throw new RuntimeException();
}
// old modifiers work only for button1
if (modifiersEX == InputEvent.BUTTON1_DOWN_MASK) {
if (modifiers != InputEvent.BUTTON1_MASK) {
System.err.println("Expected modifiers: " + InputEvent.BUTTON1_MASK);
System.err.println("Actual modifiers: " + modifiers);
throw new RuntimeException();
}
}
modifiersEX = 0;
modifiers = 0;
}
示例4: mouseDND
import java.awt.Robot; //导入方法依赖的package包/类
public static void mouseDND(Robot robot, int x1, int y1, int x2, int y2) {
int N = 20;
int x = x1;
int y = y1;
int dx = (x2 - x1) / N;
int dy = (y2 - y1) / N;
robot.mousePress(InputEvent.BUTTON1_MASK);
for (int i = 0; i < N; i++) {
robot.mouseMove(x += dx, y += dy);
}
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
示例5: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(() -> createAndShowGUI());
robot.waitForIdle();
SwingUtilities.invokeAndWait(() -> {
scale = frame.getGraphicsConfiguration().getDefaultTransform()
.getScaleX();
Point location = frame.getLocation();
Dimension size = frame.getSize();
centerX = location.x + size.width / 2;
centerY = location.y + size.height / 2;
});
robot.waitForIdle();
robot.mouseMove(centerX, centerY);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.waitForIdle();
Thread.sleep(100);
Color color = robot.getPixelColor(centerX, centerY);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
SwingUtilities.invokeAndWait(() -> frame.dispose());
if ((scale == 1 && !similar(color, COLOR_1X))
|| (scale == 2 && !similar(color, COLOR_2X))) {
throw new RuntimeException("Colors are different!");
}
}
示例6: mouseClickOnComp
import java.awt.Robot; //导入方法依赖的package包/类
static void mouseClickOnComp(Robot r, Component comp) {
Point loc = comp.getLocationOnScreen();
loc.x += comp.getWidth() / 2;
loc.y += comp.getHeight() / 2;
r.mouseMove(loc.x, loc.y);
r.delay(10);
r.mousePress(InputEvent.BUTTON1_MASK);
r.delay(10);
r.mouseRelease(InputEvent.BUTTON1_MASK);
}
示例7: click
import java.awt.Robot; //导入方法依赖的package包/类
@Override
public void click()
{
try
{
Robot robot = new Robot();
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
}
catch (AWTException e)
{
e.printStackTrace();
}
}
示例8: testCase
import java.awt.Robot; //导入方法依赖的package包/类
private static void testCase(final DefaultMutableTreeNode drag,
final DefaultMutableTreeNode drop, final float shift)
throws Exception {
Robot robot = new Robot();
robot.waitForIdle();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
Rectangle rectDrag =
jTree.getPathBounds(new TreePath(drag.getPath()));
dragPoint = new Point((int)rectDrag.getCenterX(),
(int) rectDrag.getCenterY());
SwingUtilities.convertPointToScreen(dragPoint, jTree);
Rectangle rectDrop =
jTree.getPathBounds(new TreePath(drop.getPath()));
dropPoint = new Point(rectDrop.x + 5,
(int) (rectDrop.getCenterY() + shift * rectDrop.height));
SwingUtilities.convertPointToScreen(dropPoint, jTree);
}
});
robot.mouseMove(dragPoint.x, dragPoint.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(1000);
robot.mouseMove(dropPoint.x, dropPoint.y);
robot.delay(1000);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(1000);
robot.waitForIdle();
}
示例9: clickOnTitle
import java.awt.Robot; //导入方法依赖的package包/类
public static void clickOnTitle(final Window decoratedWindow, final Robot robot) {
if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) {
Point p = getTitlePoint(decoratedWindow);
robot.mouseMove(p.x, p.y);
robot.delay(50);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.delay(50);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
}
示例10: pressOK
import java.awt.Robot; //导入方法依赖的package包/类
private static boolean pressOK(Component comp) {
JInternalFrame internalFrame
= findModalInternalFrame(comp, QUESTION);
if (internalFrame == null) {
return false;
}
JButton button = (JButton) findButton(internalFrame);
if (button == null) {
return false;
}
try {
Robot robot = new Robot();
Point location = button.getLocationOnScreen();
Rectangle bounds = button.getBounds();
int centerX = (int) (location.getX() + bounds.getWidth() / 2);
int centerY = (int) (location.getY() + bounds.getHeight() / 2);
robot.mouseMove(centerX, centerY);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
} catch (IllegalComponentStateException ignore) {
return false;
} catch (AWTException e) {
throw new RuntimeException(e);
}
return true;
}
示例11: main
import java.awt.Robot; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
Robot robot = new Robot();
robot.setAutoDelay(50);
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
createAndShowGUI();
}
});
toolkit.realSync();
Point point = getRowPointToClick(2);
robot.mouseMove(point.x, point.y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
toolkit.realSync();
}
示例12: clickAt
import java.awt.Robot; //导入方法依赖的package包/类
/**
* Move the mouse at (X,Y) screen position and then click the mouse button 1
*
* @param x the X coordinate
* @param y the Y coordinate
*/
public void clickAt( int x, int y ) {
Robot robot = getRobot();
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.delay(500);
}
示例13: mouseClick
import java.awt.Robot; //导入方法依赖的package包/类
@Override
public void mouseClick(int x, int y) {
try {
Robot robot = new Robot();
robot.mouseMove(x, y);
robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
} catch (AWTException ex) {
Logger.getLogger(Automator.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例14: moveMouse
import java.awt.Robot; //导入方法依赖的package包/类
private void moveMouse(String bestMove) {
try {
SquarePosition from = getSquarePosition(bestMove.subSequence(0, 2).toString());
SquarePosition to = getSquarePosition(bestMove.subSequence(2, 4).toString());
if (captureProcessorLlistener != null) {
if (from == null || to == null || bestMove == null || bestMove.isEmpty()) {
captureProcessorLlistener.doStop();
return;
}
}
int x1 = (int) (DesktopScreenRecorder.CAPTURE_1_X + from.point1.x) + ((int) (from.point2.x - from.point1.x) / 2);
int y1 = (int) (DesktopScreenRecorder.CAPTURE_1_Y + from.point1.y) + ((int) (from.point2.y - from.point1.y) / 2);
int x2 = (int) (DesktopScreenRecorder.CAPTURE_1_X + to.point1.x) + ((int) (to.point2.x - to.point1.x) / 2);
int y2 = (int) (DesktopScreenRecorder.CAPTURE_1_Y + to.point1.y) + ((int) (to.point2.y - to.point1.y) / 2);
Robot robot = new Robot();
robot.mouseMove(x1, y1);
robot.mousePress(InputEvent.BUTTON1_MASK);
robot.mouseMove(x2, y2);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
wait(50);
if (captureProcessorLlistener != null) {
captureProcessorLlistener.onMove(new MovePosition(from, to));
}
capturedImages.add(ImageUtils.captureImage());
} catch (Exception e) {
UIUtils.popupError(e, "ChessBoardProcessor::moveMouse");
}
}
示例15: firstShowPopup
import java.awt.Robot; //导入方法依赖的package包/类
public void firstShowPopup() throws Exception {
Point point = this.panel.getLocation();
SwingUtilities.convertPointToScreen(point, this.panel);
robot = new Robot(); // initialize shared static field first time
robot.mouseMove(point.x + 1, point.y + 1);
robot.mousePress(InputEvent.BUTTON3_MASK);
Thread.currentThread().setUncaughtExceptionHandler(this);
robot.mouseRelease(InputEvent.BUTTON3_MASK); // causes first AssertionError on EDT
}