java.awt.Robot.keyPress()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(402)

本文整理了Java中java.awt.Robot.keyPress方法的一些代码示例,展示了Robot.keyPress的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Robot.keyPress方法的具体详情如下:
包路径:java.awt.Robot
类名称:Robot
方法名:keyPress

Robot.keyPress介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

driver.findElement(By.id("SWFUpload_0")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C);        // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON);    // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH);    // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path

r.keyPress(KeyEvent.VK_ENTER);    // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

代码示例来源:origin: stackoverflow.com

textField.requestFocusInWindow();

try { 
  Robot robot = new Robot(); 

  robot.keyPress(KeyEvent.VK_ENTER); 
} catch (AWTException e) { 
e.printStackTrace(); 
}

代码示例来源:origin: RaiMan/SikuliX2

public void focusBelow() {
 if (SX.isMac()) {
  // TODO: replace this hack with a more robust method
  // Mac's hack to bring focus to the window directly underneath
  // this hack works on the assumption that the caller has
  // the input focus but no interaction area at the current
  // mouse cursor position
  // This hack does not work well with applications that
  // can receive mouse clicks without having the input focus
  // (e.g., finder, system preferences)
  //         robot.mousePress(InputEvent.BUTTON1_MASK);
  //         robot.mouseRelease(InputEvent.BUTTON1_MASK);
  // Another temporary hack to switch to the previous window on Mac
  robot.keyPress(KeyEvent.VK_META);
  robot.keyPress(KeyEvent.VK_TAB);
  robot.keyRelease(KeyEvent.VK_META);
  robot.keyRelease(KeyEvent.VK_TAB);
  // wait a little bit for the switch to complete
  robot.delay(1000);
 }
}

代码示例来源:origin: stackoverflow.com

// press Escape programatically - the print dialog must have focus, obviously
Robot r = new Robot();
r.keyPress(KeyEvent.VK_ESCAPE);
r.keyRelease(KeyEvent.VK_ESCAPE);

代码示例来源:origin: stackoverflow.com

import java.awt.Robot;
import java.awt.event.KeyEvent;

public class Notepad {

  static int keyInput[] = { KeyEvent.VK_J, KeyEvent.VK_A, KeyEvent.VK_V,
      KeyEvent.VK_A, KeyEvent.VK_SPACE };

  public static void main(String[] args) throws Exception {

    Runtime.getRuntime().exec("notepad");

    Robot robot = new Robot();
    for (int i = 0; i < keyInput.length; i++) {
      robot.keyPress(keyInput[i]);
      robot.delay(100);
    }
  }
}

代码示例来源:origin: stackoverflow.com

try {
    Robot robot = new Robot();

    // Simulate a mouse click
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    // Simulate a key press
    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);

} catch (AWTException e) {
    e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

Robot robot = new Robot();
  robot.keyPress(KeyEvent.VK_ENTER);
} catch (AWTException e) {
  e.printStackTrace();

代码示例来源:origin: stackoverflow.com

myRobot = new Robot();
} catch (AWTException e) {
  e.printStackTrace();
        myRobot.keyPress((int) myStringBuilder.charAt(i));
        myRobot.keyRelease((int) myStringBuilder.charAt(i));

代码示例来源:origin: stackoverflow.com

Robot robot = new Robot();
robot.mouseMove(xCoord, yCoord);
robot.mouseRelease(InputEvent.BUTTON1_MASK);
robot.keyPress(50);
robot.keyPress(51);

代码示例来源:origin: stackoverflow.com

String text = "Hello World";
StringSelection stringSelection = new StringSelection(text);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, stringSelection);

Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_V);
robot.keyRelease(KeyEvent.VK_CONTROL);

代码示例来源:origin: stackoverflow.com

Timer timer = new Timer(100, new ActionListener() {
 private final Robot robot = new Robot();

 public void actionPerformed(ActionEvent evt) {
  robot.mousePress(1);
  robot.mouseRelease(1);
  robot.keyPress(KeyEvent.VK_A);
 }
});

代码示例来源:origin: stackoverflow.com

Robot r = new Robot();
r.keyPress(KeyEvent.VK_ENTER);
r.keyRelease(KeyEvent.VK_ENTER);

代码示例来源:origin: stackoverflow.com

public class Test {
  public static void main(String[] args) {
    Robot robot;
    try {
      robot = new Robot();
      robot.keyPress(KeyEvent.VK_SHIFT);  
      robot.keyPress(KeyEvent.VK_SEMICOLON);  
      robot.keyRelease(KeyEvent.VK_SEMICOLON);  
      robot.keyRelease(KeyEvent.VK_SHIFT);
    } catch (AWTException e) {
      // TODO Auto-generated catch bloc
      e.printStackTrace();
    }

  }
}

代码示例来源:origin: stackoverflow.com

public class TestRobotKeys {

  private Robot robot;

  public static void main(String[] args) {
    new TestRobotKeys();
  }

  public TestRobotKeys() {
    try {
      robot = new Robot();
      robot.setAutoDelay(250);
      robot.keyPress(KeyEvent.VK_ALT);
      robot.keyPress(KeyEvent.VK_1);
      robot.keyRelease(KeyEvent.VK_1);
      robot.keyPress(KeyEvent.VK_2);
      robot.keyRelease(KeyEvent.VK_2);
      robot.keyPress(KeyEvent.VK_3);
      robot.keyRelease(KeyEvent.VK_4);
      robot.keyRelease(KeyEvent.VK_ALT);
    } catch (AWTException ex) {
      ex.printStackTrace();
    }
  }

}

代码示例来源:origin: stackoverflow.com

try {
  Robot robot = new Robot();

  // Simulate a mouse click
  robot.mousePress(InputEvent.BUTTON1_MASK);
  robot.mouseRelease(InputEvent.BUTTON1_MASK);

  // Simulate a key press
  robot.keyPress(KeyEvent.VK_SHIFT);
  robot.keyPress(KeyEvent.VK_TAB);
  robot.keyRelease(KeyEvent.VK_TAB);
  robot.keyRelease(KeyEvent.VK_SHIFT);
} catch (AWTException e) {
  e.printStackTrace();
}

代码示例来源:origin: stackoverflow.com

Robot r = new Robot();
doLeftMouseClick(r, 272, 241);
r.delay(1000);
doLeftMouseClick(r, 272, 241);
r.keyPress(KeyEvent.SHIFT_MASK);
doLeftMouseClickEvent(r, 272, 241, 1);
doLeftMouseClickEvent(r, 529, 242, 2);
r.keyRelease(KeyEvent.SHIFT_MASK);
r.keyPress(KeyEvent.CTRL_MASK);
r.keyPress(KeyEvent.VK_C);
r.keyRelease(KeyEvent.CTRL_MASK);

代码示例来源:origin: stackoverflow.com

Robot r = new Robot();
r.keyPress(KeyEvent.VK_CONTROL);
r.keyPress(KeyEvent.VK_SHIFT);
r.keyPress(KeyEvent.VK_F1);
r.keyRelease(KeyEvent.VK_F1);
r.keyRelease(KeyEvent.VK_SHIFT);
r.keyRelease(KeyEvent.VK_CONTROL);

代码示例来源:origin: stackoverflow.com

public void switchFocus() {
 try {
  Robot r = new Robot();
  r.keyPress(KeyEvent.VK_ALT);
  r.keyPress(KeyEvent.VK_TAB);
  r.keyRelease(KeyEvent.VK_ALT);
  r.keyRelease(KeyEvent.VK_TAB);
 } catch(AWTException e) {
  // handle
 }
}

代码示例来源:origin: stackoverflow.com

driver.findElement(By.id("up-drop-zone-input")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C);        // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON);    // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH);    // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path

r.keyPress(KeyEvent.VK_ENTER);    // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

代码示例来源:origin: stackoverflow.com

driver.findElement(By.id("wkFileUpload")).click();
Robot r = new Robot();
r.keyPress(KeyEvent.VK_C);        // C
r.keyRelease(KeyEvent.VK_C);
r.keyPress(KeyEvent.VK_COLON);    // : (colon)
r.keyRelease(KeyEvent.VK_COLON);
r.keyPress(KeyEvent.VK_SLASH);    // / (slash)
r.keyRelease(KeyEvent.VK_SLASH);
// etc. for the whole file path

r.keyPress(KeyEvent.VK_ENTER);    // confirm by pressing Enter in the end
r.keyRelease(KeyEvent.VK_ENTER);

相关文章