當前位置: 首頁>>代碼示例>>Java>>正文


Java Robot.keyPress方法代碼示例

本文整理匯總了Java中java.awt.Robot.keyPress方法的典型用法代碼示例。如果您正苦於以下問題:Java Robot.keyPress方法的具體用法?Java Robot.keyPress怎麽用?Java Robot.keyPress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.awt.Robot的用法示例。


在下文中一共展示了Robot.keyPress方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import java.awt.Robot; //導入方法依賴的package包/類
@Override
public void execute(@NotNull String pattern) {
  try {

    Robot r = new Robot();
    r.keyPress(157);
    r.keyPress(90);

    r.keyRelease(90);
    r.keyRelease(157);


  } catch (AWTException e) {
    e.printStackTrace();
  }
  SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
  SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);

}
 
開發者ID:vaclav,項目名稱:voicemenu,代碼行數:20,代碼來源:Command_TransformationMenu.java

示例2: checkFileChooser

import java.awt.Robot; //導入方法依賴的package包/類
private static void checkFileChooser() throws Exception {
    if (System.getSecurityManager() == null) {
        throw new RuntimeException("Security manager is not set!");
    }

    Robot robot = new Robot();
    robot.setAutoDelay(50);

    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            fileChooser = new JFileChooser();
            fileChooser.showOpenDialog(null);
            fileChooserIsShown = true;
            System.out.println("Start file chooser: " + fileChooserIsShown);
        }
    });

    long time = System.currentTimeMillis();
    while (fileChooser == null) {
        if (System.currentTimeMillis() - time >= 10000) {
            throw new RuntimeException("FileChoser is not shown!");
        }
        Thread.sleep(500);
    }

    Thread.sleep(500);
    robot.keyPress(KeyEvent.VK_ESCAPE);
    robot.keyRelease(KeyEvent.VK_ESCAPE);
    System.exit(0);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:32,代碼來源:bug8062561.java

示例3: main

import java.awt.Robot; //導入方法依賴的package包/類
public static void main(final String[] args) throws AWTException {
    final boolean dump = Boolean.parseBoolean(args[0]);
    final Window w = new Frame() {
        @Override
        public void list(final PrintStream out, final int indent) {
            super.list(out, indent);
            dumped = true;
        }
    };
    w.setSize(200, 200);
    w.setLocationRelativeTo(null);
    w.setVisible(true);

    final Robot robot = new Robot();
    robot.setAutoDelay(50);
    robot.setAutoWaitForIdle(true);
    robot.mouseMove(w.getX() + w.getWidth() / 2,
                    w.getY() + w.getHeight() / 2);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_SHIFT);
    robot.keyPress(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_F1);
    robot.keyRelease(KeyEvent.VK_SHIFT);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    w.dispose();
    if (dumped != dump) {
        throw new RuntimeException("Exp:" + dump + ", actual:" + dumped);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:34,代碼來源:DumpOnKey.java

示例4: execute

import java.awt.Robot; //導入方法依賴的package包/類
@Override
public void execute(@NotNull String pattern) {

  try {
    Robot r = new Robot();
    r.keyPress(157);
    r.keyPress(90);

    r.keyRelease(90);
    r.keyRelease(157);

  } catch (AWTException e) {
    e.printStackTrace();
  }
  SelectionUtil.selectNode(_context.getEditorContext(), _context.getNode());
  SelectionUtil.selectCell(_context.getEditorContext(), _context.getNode(), SelectionManager.FIRST_ERROR_CELL + "|" + SelectionManager.FOCUS_POLICY_CELL + "|" + SelectionManager.FIRST_EDITABLE_CELL + "|" + SelectionManager.FIRST_CELL);

}
 
開發者ID:vaclav,項目名稱:voicemenu,代碼行數:19,代碼來源:Timeout_TransformationMenu.java

示例5: writeString

import java.awt.Robot; //導入方法依賴的package包/類
private static void writeString(String s, Robot robot) throws InterruptedException {
    for (char c : s.toCharArray()) {
        if (isupper(c))
            robot.keyPress(KeyEvent.VK_SHIFT);

        if (c == ':') {
            robot.keyPress(KeyEvent.VK_SHIFT);
            robot.keyPress(KeyEvent.VK_SEMICOLON);
            robot.keyRelease(KeyEvent.VK_SEMICOLON);
            robot.keyRelease(KeyEvent.VK_SHIFT);
        } else {
            robot.keyPress(Character.toUpperCase(c));
            robot.keyRelease(Character.toUpperCase(c));
        }
        if (isupper(c))
            robot.keyRelease(KeyEvent.VK_SHIFT);

        Thread.sleep(15);
    }
}
 
開發者ID:kenziyuliu,項目名稱:TypeFast,代碼行數:21,代碼來源:TypeFast.java

示例6: pasteAll

import java.awt.Robot; //導入方法依賴的package包/類
public void pasteAll() throws Exception
{
	re = new Robot();
	re.keyPress(KeyEvent.VK_CONTROL);
	re.keyPress(KeyEvent.VK_V);
	re.keyRelease(KeyEvent.VK_CONTROL);
	re.keyRelease(KeyEvent.VK_V);
}
 
開發者ID:GladsonAntony,項目名稱:WebAutomation_AllureParallel,代碼行數:9,代碼來源:BaseMethod.java

示例7: testPopupAction

import java.awt.Robot; //導入方法依賴的package包/類
private static void testPopupAction() throws Exception {

        SwingUtilities.invokeAndWait(bug8133039::createAndShowGUI);

        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.waitForIdle();

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        if (ACTION_ACCEPTED_CALLS != 1) {
            throw new RuntimeException("Method accept is not invoked!");
        }

        if (ACTION_PERFORMED_CALLS != 1) {
            throw new RuntimeException("Method actionPerformed is not invoked!");
        }

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        robot.waitForIdle();

        if (ACTION_ACCEPTED_CALLS != 2) {
            throw new RuntimeException("Method accept is not invoked!");
        }

        if (ACTION_PERFORMED_CALLS != 1) {
            throw new RuntimeException("Method actionPerformed is invoked twice!");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:33,代碼來源:bug8133039.java

示例8: checkAltRightClickEvent

import java.awt.Robot; //導入方法依賴的package包/類
private void checkAltRightClickEvent(int eventToCheck) throws InterruptedException, InvocationTargetException, AWTException {
    events = eventToCheck;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON3_MASK);
    r.mouseRelease(InputEvent.BUTTON3_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(button, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(b).keyDown(Keys.ALT).contextClick().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());
    // Wait till the previous click is processed by the EDT
    Thread.sleep(500);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:40,代碼來源:NativeEventsTest.java

示例9: selectAll

import java.awt.Robot; //導入方法依賴的package包/類
public void selectAll() throws Exception
{
	re = new Robot();
	re.keyPress(KeyEvent.VK_CONTROL);
	re.keyPress(KeyEvent.VK_A);
	re.keyRelease(KeyEvent.VK_CONTROL);
	re.keyRelease(KeyEvent.VK_A);
}
 
開發者ID:GladsonAntony,項目名稱:WebAutomation_AllureParallel,代碼行數:9,代碼來源:BaseMethod.java

示例10: main

import java.awt.Robot; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
    Test8013370 task = new Test8013370();
    invokeAndWait(task);

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

    invokeAndWait(task);
    task.validate();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:14,代碼來源:Test8013370.java

示例11: robotZoomOut

import java.awt.Robot; //導入方法依賴的package包/類
public void robotZoomOut() throws Exception 
{
	re = new Robot();
	re.keyPress(KeyEvent.VK_CONTROL);
	re.keyPress(KeyEvent.VK_SUBTRACT);
	re.keyRelease(KeyEvent.VK_SUBTRACT);
	re.keyRelease(KeyEvent.VK_CONTROL);
}
 
開發者ID:GladsonAntony,項目名稱:WebAutomation_AllureParallel,代碼行數:9,代碼來源:BaseMethod.java

示例12: escape

import java.awt.Robot; //導入方法依賴的package包/類
private void escape () {
	try {
		Robot robot = new Robot();
		robot.keyPress(KeyEvent.VK_ESCAPE);
	} catch (AWTException e) {
	}
}
 
開發者ID:gw4e,項目名稱:gw4e.project,代碼行數:8,代碼來源:GraphPart.java

示例13: hitKey

import java.awt.Robot; //導入方法依賴的package包/類
private static void hitKey(Robot robot, int mode, int keycode) {
    robot.keyPress(mode);
    robot.keyPress(keycode);
    robot.keyRelease(mode);
    robot.keyRelease(keycode);
    robot.waitForIdle();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:bug8033699.java

示例14: main

import java.awt.Robot; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        Frame frame = new Frame();
        frame.setSize(300, 300);
        frame.setVisible(true);
        toolkit.realSync();

        Robot robot = new Robot();

        robot.keyPress(KeyEvent.VK_DELETE);
        robot.keyRelease(KeyEvent.VK_DELETE);
        toolkit.realSync();

        frame.dispose();

        if (eventsCount != 3) {
            throw new RuntimeException("Wrong number of key events: " + eventsCount);
        }
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:KeyCharTest.java

示例15: enterInput

import java.awt.Robot; //導入方法依賴的package包/類
private static void enterInput(Robot robotKeyInput, int keyInputs[][]) {
    for (int i = 0; i < keyInputs.length; i++) {
        String strKeyInput = "KeyPress=>";
        final int noOfKeyInputs = keyInputs[i].length;
        for (int j = 0; j < noOfKeyInputs; j++) {
            robotKeyInput.keyPress(keyInputs[i][j]);
            strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
        }

        strKeyInput += "KeyRelease=>";
        for (int j = noOfKeyInputs - 1; j >= 0; j--) {
            robotKeyInput.keyRelease(keyInputs[i][j]);
            strKeyInput += (Integer.toHexString(keyInputs[i][j])) + ":";
        }
        System.out.println(strKeyInput);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:MissingCharsKorean.java


注:本文中的java.awt.Robot.keyPress方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。