当前位置: 首页>>代码示例>>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;未经允许,请勿转载。