Java Code Examples for java.awt.Robot#keyRelease()
The following examples show how to use
java.awt.Robot#keyRelease() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiddenDefaultButtonTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void test() throws Exception { // Create Robot Robot testRobot = new Robot(); testRobot.waitForIdle(); testRobot.keyPress(KeyEvent.VK_ENTER); testRobot.delay(20); testRobot.keyRelease(KeyEvent.VK_ENTER); testRobot.delay(200); testRobot.keyPress(KeyEvent.VK_ENTER); testRobot.delay(20); testRobot.keyRelease(KeyEvent.VK_ENTER); testRobot.waitForIdle(); if (ButtonClickCount != 0) { disposeTestUI(); throw new RuntimeException("DefaultButton is pressed even if it is invisible"); } }
Example 2
Source File: KeyCharTest.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example 3
Source File: KeyCharTest.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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); } }
Example 4
Source File: KeyCharTest.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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); } }
Example 5
Source File: DeadKeySystemAssertionDialog.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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(); }
Example 6
Source File: MultiResolutionSplashTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 7
Source File: ConsumedKeyTest.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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(); } } }
Example 8
Source File: bug8057893.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(50); SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); EventQueue.invokeAndWait(() -> { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"}); comboBox.setEditable(true); comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if ("comboBoxEdited".equals(e.getActionCommand())) { isComboBoxEdited = true; } } }); frame.add(comboBox); frame.pack(); frame.setVisible(true); comboBox.requestFocusInWindow(); }); toolkit.realSync(); robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); toolkit.realSync(); if(!isComboBoxEdited){ throw new RuntimeException("ComboBoxEdited event is not fired!"); } }
Example 9
Source File: Test8013370.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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(); }
Example 10
Source File: bug8062561.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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); }
Example 11
Source File: GoToLine.java From netbeans with Apache License 2.0 | 5 votes |
public static void goToLine(int line,Robot robot) { GoToLine op=new GoToLine(); java.awt.Point p; int x,y; String s=String.valueOf(line); int c; robot.waitForIdle(); robot.delay(200); for (int i=0;i < s.length();i++) { c=(int)s.charAt(i); robot.keyPress(c); robot.delay(50); robot.keyRelease(c); } p=op.btGoto().getLocationOnScreen(); x=p.x+op.btGoto().getWidth()/2; y=p.y+op.btGoto().getHeight()/2; robot.mouseMove(x,y); robot.mousePress(InputEvent.BUTTON1_MASK); robot.delay(50); robot.mouseRelease(InputEvent.BUTTON1_MASK); robot.delay(50); robot.waitForIdle(); while (op.isVisible()) { robot.delay(50); } }
Example 12
Source File: NativeEventsTest.java From marathonv5 with Apache License 2.0 | 5 votes |
public void exitedGeneratesSameEvents() throws Throwable { events = MouseEvent.MOUSE_EXITED; 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.BUTTON1_MASK); r.mouseRelease(InputEvent.BUTTON1_MASK); 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); 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(); new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).moveToElement(t).keyUp(Keys.ALT).perform(); AssertJUnit.assertEquals(expected, t.getText()); }
Example 13
Source File: DumpOnKey.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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); } }
Example 14
Source File: bug8057893.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Robot robot = new Robot(); robot.setAutoDelay(50); SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit(); EventQueue.invokeAndWait(() -> { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"}); comboBox.setEditable(true); comboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if ("comboBoxEdited".equals(e.getActionCommand())) { isComboBoxEdited = true; } } }); frame.add(comboBox); frame.pack(); frame.setVisible(true); comboBox.requestFocusInWindow(); }); toolkit.realSync(); robot.keyPress(KeyEvent.VK_A); robot.keyRelease(KeyEvent.VK_A); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); toolkit.realSync(); if(!isComboBoxEdited){ throw new RuntimeException("ComboBoxEdited event is not fired!"); } }
Example 15
Source File: MultiResolutionSplashTest.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 16
Source File: MultiResolutionSplashTest.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
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!"); } }
Example 17
Source File: NativeEventsTest.java From marathonv5 with Apache License 2.0 | 4 votes |
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); }
Example 18
Source File: Module.java From netbeans with Apache License 2.0 | 4 votes |
public void test_4_9_3() { switchToHTTPServerNode(); PropertySheetOperator pw = new PropertySheetOperator("HTTP Server"); psto = pw.getPropertySheetTabOperator("Properties"); TextFieldProperty tf=new TextFieldProperty(psto,"Hosts with Granted Access"); tf.setValue("Selected Hosts: "); tf.openEditor(); try { dop=new NbDialogOperator("Hosts with Granted Access"); } catch(Exception ex) { //dop.close(); pw.close(); throw new AssertionFailedErrorException("No 'Hosts with Granted Access' dialog appears",ex); } dop.pushKey(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK); dop.releaseKey(java.awt.event.KeyEvent.VK_G, java.awt.event.InputEvent.ALT_MASK); /* JTextAreaOperator jt = new JTextAreaOperator(dop); jt.pushKey(java.awt.event.KeyEvent.VK_T); jt.releaseKey(java.awt.event.KeyEvent.VK_T); jt.pushKey(java.awt.event.KeyEvent.VK_E); jt.releaseKey(java.awt.event.KeyEvent.VK_E); jt.pushKey(java.awt.event.KeyEvent.VK_S); jt.releaseKey(java.awt.event.KeyEvent.VK_S); jt.pushKey(java.awt.event.KeyEvent.VK_T); jt.releaseKey(java.awt.event.KeyEvent.VK_T); */ try { Robot rb=new java.awt.Robot(); /* rb.keyPress(java.awt.event.KeyEvent.VK_ALT); rb.keyPress(java.awt.event.KeyEvent.VK_G); rb.keyRelease(java.awt.event.KeyEvent.VK_G); rb.keyRelease(java.awt.event.KeyEvent.VK_ALT); */ rb.keyPress(java.awt.event.KeyEvent.VK_T); rb.keyRelease(java.awt.event.KeyEvent.VK_T); rb.keyPress(java.awt.event.KeyEvent.VK_E); rb.keyRelease(java.awt.event.KeyEvent.VK_E); rb.keyPress(java.awt.event.KeyEvent.VK_S); rb.keyRelease(java.awt.event.KeyEvent.VK_S); rb.keyPress(java.awt.event.KeyEvent.VK_T); rb.keyRelease(java.awt.event.KeyEvent.VK_T); } catch (Exception AWTException) { System.out.println("AWTException in test_4_9_3"); // NOI18N } dop.ok(); value=tf.getValue(); if (!value.equals("Selected Hosts: test")) { pw.close(); fail("Invalid 'Hosts with Granted Access' field value ("+value+")"); } pw.close(); }
Example 19
Source File: ButtonGroupLayoutTraversalTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { SwingUtilities.invokeAndWait(() -> changeLAF()); SwingUtilities.invokeAndWait(() -> initLayout(nx, ny)); Robot robot = new Robot(); robot.setAutoDelay(100); robot.waitForIdle(); robot.delay(200); for (int i = 0; i < nx * ny - nx * ny / 2 - 1; i++) { robot.keyPress(KeyEvent.VK_RIGHT); robot.keyRelease(KeyEvent.VK_RIGHT); } for (int i = 0; i < nx * ny / 2; i++) { robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); } robot.waitForIdle(); robot.delay(200); for (int i = 0; i < nx * ny; i++) { if (focusCnt[i] < 1) { SwingUtilities.invokeLater(window::dispose); throw new RuntimeException("Component " + i + " is not reachable in the forward focus cycle"); } else if (focusCnt[i] > 1) { SwingUtilities.invokeLater(window::dispose); throw new RuntimeException("Component " + i + " got focus more than once in the forward focus cycle"); } } for (int i = 0; i < nx * ny / 2; i++) { robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); } for (int i = 0; i < nx * ny - nx * ny / 2 - 1; i++) { robot.keyPress(KeyEvent.VK_LEFT); robot.keyRelease(KeyEvent.VK_LEFT); } robot.keyPress(KeyEvent.VK_SHIFT); robot.keyPress(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_TAB); robot.keyRelease(KeyEvent.VK_SHIFT); robot.waitForIdle(); robot.delay(200); for (int i = 0; i < nx * ny; i++) { if (focusCnt[i] < 2) { SwingUtilities.invokeLater(window::dispose); throw new RuntimeException("Component " + i + " is not reachable in the backward focus cycle"); } else if (focusCnt[i] > 2) { SwingUtilities.invokeLater(window::dispose); throw new RuntimeException("Component " + i + " got focus more than once in the backward focus cycle"); } } SwingUtilities.invokeLater(window::dispose); }
Example 20
Source File: bug8033699.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private static void hitKey(Robot robot, int keycode) { robot.keyPress(keycode); robot.keyRelease(keycode); robot.waitForIdle(); }