Java 8 Robot - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Robot class.

This code example shows how to use the following methods:mouseMove, mousePress, mouseRelease, setAutoDelay
    private static JTable table;
 
    public static void main(String args[]) throws Exception {
 
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        Robot robot = new Robot();
        robot.setAutoDelay(50);
 
        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
 
            public void run() { 
                createAndShowGUI(); 
            } 
        }); 
 
        toolkit.realSync();
 
        clickMouse(robot, 0, 0);
        Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER);
        toolkit.realSync();

7
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:delay, mouseMove, mousePress, mouseRelease
    public void start() { 
        frame.setVisible(true);
        Util.waitTillShown(frame);
 
        Point loc = frame.getLocationOnScreen();
        robot.mouseMove(loc.x + frame.getWidth() / 4, loc.y + frame.getInsets().top / 2);
        robot.delay(50);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.delay(50);
        robot.mouseMove(loc.x + 100, loc.y + 50);
        robot.delay(50);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
 
        Util.waitForIdle(robot);
 
        loc = frame.getLocation();
        robot.mouseMove(loc.x + frame.getWidth() / 2, loc.y + frame.getHeight() / 2);
        Util.waitForIdle(robot);
 
        if (!(frame.getLocation().equals(loc))) {

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:delay, keyPress, keyRelease
        JTextArea textarea = new JTextArea(40, 10);
        frame.getContentPane().add(textarea);
 
        frame.pack();
        frame.setVisible(true);
        Util.waitForIdle(robot);
 
        if (!frame.isActive()) {
            throw new RuntimeException("Test Fialed: frame isn't active");
        } 
 
        // verify if checkbox has focus 
        if (!checkbox.isFocusOwner()) {
            checkbox.requestFocusInWindow();
            Util.waitForIdle(robot);
            if (!checkbox.isFocusOwner()) {
                throw new RuntimeException("Test Failed: checkbox doesn't have focus");
            } 
        } 
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:delay, keyPress, keyRelease, waitForIdle
    } 
 
  } 
 
  public void fullScreen() { 
    robot.delay(5000);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_ALT);
    robot.keyPress(KeyEvent.VK_TAB);
    robot.waitForIdle();
    robot.keyRelease(KeyEvent.VK_ALT);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_F11);
    robot.waitForIdle();
 
  } 
 
  @Override 
  public void runFile(FileInfo fileInfo) {
    // For now, assume that media player is the default player. 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:delay, keyPress, keyRelease
        if (!Util.trackFocusGained(frameButton, showAction, 2000, false)) {
            System.out.println("Test error: wrong initial focus!");
            return; 
        } 
 
        robot.keyPress(KeyEvent.VK_SPACE);
        robot.delay(50);
        robot.keyRelease(KeyEvent.VK_SPACE);
 
        Util.waitForCondition(lock, 2000);
        Util.waitForIdle(robot);
    } 
} 
 
class TestKFM extends DefaultKeyboardFocusManager {
    Robot robot;
    public TestKFM(Robot robot) {
        this.robot = robot;
    } 
    protected synchronized void enqueueKeyEvents(long after, Component untilFocused) {
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:
    private static Document doc;
    private static Robot robot;
 
    public static void main(String[] args) throws Exception {
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        robot = new Robot();
 
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() { 
                createAndShowGUI(); 
            } 
        }); 
 
        toolkit.realSync();
 
        Util.hitKeys(robot, KeyEvent.VK_HOME);
        Util.hitKeys(robot, KeyEvent.VK_1);
 
        toolkit.realSync();
 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:keyPress, keyRelease
 
import org.gmote.server.PlatformUtil; 
 
public class CommonOperations { 
  public static void sendCloseCommand() throws AWTException {
    Robot robot = new Robot();
    if (PlatformUtil.isMac()) { 
      robot.keyPress(KeyEvent.VK_META);
      robot.keyPress(KeyEvent.VK_W);
      robot.keyRelease(KeyEvent.VK_W);
      robot.keyRelease(KeyEvent.VK_META);
    } else { 
      robot.keyPress(KeyEvent.VK_ALT);
      robot.keyPress(KeyEvent.VK_F4);
      robot.keyRelease(KeyEvent.VK_F4);
      robot.keyRelease(KeyEvent.VK_ALT);
    } 
  } 
} 
6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:keyPress, keyRelease
	 * Process the command from client 
	 * @param command the command code 
	 */ 
	private void processCommand(int command) {
		try { 
			Robot robot = new Robot();
			switch (command) {
	    	case KEY_RIGHT:
	    		robot.keyPress(KeyEvent.VK_RIGHT);
	    		System.out.println("Right");
	    		// release the key after it is pressed. Otherwise the event just keeps getting trigged	    		 
	    		robot.keyRelease(KeyEvent.VK_RIGHT);
	    		break; 
	    	case KEY_LEFT:
	    		robot.keyPress(KeyEvent.VK_LEFT);
	    		System.out.println("Left");
	    		// release the key after it is pressed. Otherwise the event just keeps getting trigged	    		 
	    		robot.keyRelease(KeyEvent.VK_LEFT);
	    		break; 
			} 

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:keyPress, keyRelease
    	 
    } 
    public void doType(boolean altPressed, boolean ctrlPressed, boolean shiftPressed, int... keyCodes ) {
       	 
    	if (altPressed)
    		robot.keyPress(KeyEvent.VK_ALT); //*/
    	if (ctrlPressed)
    		robot.keyPress(KeyEvent.VK_CONTROL);
    	if (shiftPressed)
    		robot.keyPress(KeyEvent.VK_SHIFT);//*/
    	 
        doType(keyCodes, 0, keyCodes.length);
         
    	robot.keyRelease(KeyEvent.VK_ALT);//*/
    	robot.keyRelease(KeyEvent.VK_CONTROL);
    	robot.keyRelease(KeyEvent.VK_SHIFT);//*/
    } 
 
    public void doType( int... keyCodes ) {
        doType(keyCodes, 0, keyCodes.length);

6
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
This code example shows how to use the following methods:delay
                    System.out.println(we);
                } 
            }); 
 
        // we need this delay so WM can not treat two clicks on title as double click 
        robot.delay(500);
        Util.clickOnTitle(owner_frame, robot);
        Util.waitForIdle(robot);
 
        System.out.println("test passed");
    } 
 
    private static void setFocus(final Component comp, final Robot r) {
        if (comp.hasFocus()) {
            return; 
        } 
 
        Util.clickOnComp(comp, r);
        Util.waitForIdle(r);
 

5
CodeRank
Contextual code suggestions in your IDE  Get Codota for Java
See Code Examples for Java 8 Robot Methods: