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


Java Robot.keyRelease方法代碼示例

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


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

示例1: 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

示例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: 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

示例4: main

import java.awt.Robot; //導入方法依賴的package包/類
public static void main(String [] args) throws Exception {
    Robot robot = new Robot();
    SwingUtilities.invokeAndWait(() -> {
        try {
            UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        tf = new TestNimbusOverride();
        tf.pack();
        tf.setVisible(true);
    });
    robot.setAutoDelay(100);
    robot.waitForIdle();
    robot.keyPress(KeyEvent.VK_SPACE);
    robot.keyRelease(KeyEvent.VK_SPACE);
    robot.waitForIdle();
    SwingUtilities.invokeAndWait(() -> tf.dispose());
    if (!passed) {
            throw new RuntimeException(
                    "Setting Nimbus.Overrides property affects custom keymap installation");
        }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TestNimbusOverride.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: 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

示例7: 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

示例8: testFocus

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

        System.out.println("Focus Test!");
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        Frame frame = new Frame();
        frame.setSize(100, 100);
        String test = "123";
        TextField textField = new TextField(test);
        textField.selectAll();
        frame.add(textField);
        frame.setVisible(true);
        robot.waitForIdle();

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

        frame.dispose();
        if (!textField.getText().equals("ab")) {
            throw new RuntimeException("Focus is lost!");
        }
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:26,代碼來源:UnixMultiResolutionSplashTest.java

示例9: 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,代碼行數:18,代碼來源:WorkSpace_TransformationMenu.java

示例10: 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, 200);

        TextField textField = new TextField();
        frame.add(textField);

        frame.setVisible(true);
        toolkit.realSync();

        textField.requestFocus();
        toolkit.realSync();

        // Check that the system assertion dialog does not block Java
        Robot robot = new Robot();
        robot.setAutoDelay(50);
        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        frame.setVisible(false);
        frame.dispose();
    }
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:26,代碼來源:DeadKeySystemAssertionDialog.java

示例11: pressKey

import java.awt.Robot; //導入方法依賴的package包/類
/**
 * Using AWT robot presses and immediately releases certain key.
 * @param code Code of the key to be pressed.
 */
private void pressKey(int code) {
    try {
        Robot robot = new Robot();
        robot.keyPress(code);
        robot.keyRelease(code);
    } catch (AWTException ex) {
        Exceptions.printStackTrace(ex);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:14,代碼來源:AntSanityTest.java

示例12: robotKeyPressTest

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

        SwingUtilities.invokeAndWait(() -> {
            frame = new Frame();
            frame.setSize(300, 300);
            frame.setVisible(true);
        });

        Robot robot = new Robot();
        robot.waitForIdle();
        Point pt = frame.getLocationOnScreen();
        robot.mouseMove(((int) pt.getX() + frame.getWidth()) / 2,
                ((int) pt.getY() + frame.getHeight()) / 2);
        robot.waitForIdle();
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_ENTER);
        robot.waitForIdle();
        robot.keyRelease(KeyEvent.VK_ENTER);
        robot.waitForIdle();

        SwingUtilities.invokeAndWait(() -> {
            frame.dispose();
        });
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:RobotCrash.java

示例13: find

import java.awt.Robot; //導入方法依賴的package包/類
public static void find(String text,Robot robot) {
    Find op=new Find();
    robot.waitForIdle();
    java.awt.Point p=op.cboFindWhat().getLocationOnScreen();
    int x=p.x+op.cboFindWhat().getWidth()/2;
    int y=p.y+op.cboFindWhat().getHeight()/2;
    robot.mouseMove(x,y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.delay(50);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    char c;
    boolean upper;
    for (int i=0;i < text.length();i++) {
        c=text.charAt(i);
        if (Character.isUpperCase(c)) {
            upper=true;
        } else {
            upper=false;
            c=(char)(Character.toUpperCase((char)c));
        }
        if (upper) {
            robot.keyPress(KeyEvent.VK_SHIFT);
        }
        robot.keyPress((int)c);
        robot.delay(5);
        robot.keyRelease((int)c);
        robot.delay(5);
        if (upper) {
            robot.keyRelease(KeyEvent.VK_SHIFT);
        }
    }
    p=op.btFind().getLocationOnScreen();
    x=p.x+op.btFind().getWidth()/2;
    y=p.y+op.btFind().getHeight()/2;
    robot.mouseMove(x,y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.delay(50);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.delay(50);
    robot.waitForIdle();
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:42,代碼來源:Find.java

示例14: TestPopupMenu

import java.awt.Robot; //導入方法依賴的package包/類
public TestPopupMenu() throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(200);
    try {
        SwingUtilities.invokeAndWait(() -> {
            try {
                createAndShowUI();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        blockTillDisplayed(label);
        robot.waitForIdle();
        robot.mouseMove(p.x + d.width/2, p.y + d.height/2);
        robot.mousePress(InputEvent.BUTTON3_DOWN_MASK);
        robot.mouseRelease(InputEvent.BUTTON3_DOWN_MASK);
        robot.waitForIdle();
        robot.keyPress(KeyEvent.VK_CONTROL);
        robot.keyPress(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_U);
        robot.keyRelease(KeyEvent.VK_CONTROL);
        robot.waitForIdle();
        JPopupMenu popup = label.getComponentPopupMenu();
        if (popup != null && popup.isVisible()) {
            throw new RuntimeException("Popup is visible in wrong internal frame");
        }
    } finally {
        SwingUtilities.invokeAndWait(()->frame.dispose());
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:31,代碼來源:TestPopupMenu.java

示例15: test

import java.awt.Robot; //導入方法依賴的package包/類
private static void test(final int key) throws Exception {
    passed = false;
    try {
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            JComboBox<String> combo = new JComboBox<>(new String[]{"one", "two", "three"});
            JPanel panel = new JPanel();
            panel.add(combo);
            combo.requestFocusInWindow();
            frame.setBounds(100, 150, 300, 100);
            addAction(panel, key);
            frame.add(panel);
            frame.setVisible(true);
        });

        Robot robot = new Robot();
        robot.waitForIdle();
        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
        robot.keyPress(key);
        robot.waitForIdle();
        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
        robot.keyRelease(key);
        robot.waitForIdle();
        ((SunToolkit)Toolkit.getDefaultToolkit()).realSync();
        if (!passed) {
            throw new RuntimeException("FAILED: " + KeyEvent.getKeyText(key) + " was consumed by combo box");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }

}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:35,代碼來源:ConsumedKeyTest.java


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