List of usage examples for java.awt Robot keyRelease
public synchronized void keyRelease(int keycode)
From source file:com.netease.dagger.BrowserEmulator.java
/** * Close previous tab in browser//w ww . j a v a2 s . c o m */ public void closePreviousTAB() { pause(stepInterval); try { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_PAGE_UP); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_PAGE_UP); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_W); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_W); } catch (Exception e) { e.printStackTrace(); handleFailure("Failed to close previous TAB"); } logger.info("Success to close previous TAB"); }
From source file:com.netease.dagger.BrowserEmulator.java
/** * Mimic system-level keyboard event// w w w . ja v a 2s . c om * * @param keyCode * http://www.cnblogs.com/hsapphire/archive/2009/12/16/1625642.html */ public void pressKeyboard(int keyCode) { pause(stepInterval); Robot rb = null; try { rb = new Robot(); } catch (AWTException e) { e.printStackTrace(); } rb.keyPress(keyCode); // press key rb.delay(100); // delay 100ms rb.keyRelease(keyCode); // release key logger.info("Pressed key with code " + keyCode); }
From source file:faa.cucumber.pages.FaaHomePage.java
public void wKeyRelease() { waitABit(2000);//from ww w.j a v a2 s . co m Robot robot; try { robot = new Robot(); System.out.println("Release W Key"); robot.keyRelease(java.awt.event.KeyEvent.VK_W); System.out.println("W Key Release"); waitABit(1000); } catch (AWTException e) { System.out.println("Error has occured when attempting to Refresh Browser Window!!"); e.printStackTrace(); } }
From source file:faa.cucumber.pages.FaaHomePage.java
public void switchReleaseControlTab() { waitABit(2000);// ww w. j a v a2 s . c o m Robot robot; try { robot = new Robot(); System.out.println("Release Control Tab Keys"); System.out.println("TAB Key keyRelease"); robot.keyRelease(KeyEvent.VK_TAB); System.out.println("TAB Key keyRelease"); robot.keyRelease(KeyEvent.VK_CONTROL); System.out.println("Control Key keyRelease"); // robot.keyRelease(KeyEvent.VK_TAB); // System.out.println("TAB Key keyRelease" ); // robot.keyRelease(KeyEvent.VK_CONTROL); // System.out.println("Control Key Released" ); // robot.keyRelease(KeyEvent.VK_TAB); // System.out.println("TAB Key Released" ); // System.out.println("Browser Tabs have been switched."); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:faa.cucumber.pages.FaaHomePage.java
public void switchFaaBrowserRefresh() { waitABit(2000);//from ww w. j a va 2 s . c o m Robot robot; try { robot = new Robot(); System.out.println("Refresh Browser Window"); robot.keyPress(java.awt.event.KeyEvent.VK_F5); System.out.println("F5 Key Pressed"); waitABit(1000); robot.keyRelease(java.awt.event.KeyEvent.VK_F5); System.out.println("F5 Key Released"); } catch (AWTException e) { System.out.println("Error has occured when attempting to Refresh Browser Window!!"); e.printStackTrace(); } }
From source file:faa.cucumber.pages.FaaHomePage.java
public void switchBrowserTabs() { waitABit(2000);// w w w.j a v a 2 s . com Robot robot; try { robot = new Robot(); System.out.println("Switching Tabs"); robot.keyPress(KeyEvent.VK_CONTROL); System.out.println("Control Key Pressed"); robot.keyPress(KeyEvent.VK_TAB); System.out.println("TAB Key Pressed"); robot.keyRelease(KeyEvent.VK_CONTROL); System.out.println("Control Key Released"); robot.keyRelease(KeyEvent.VK_TAB); System.out.println("TAB Key Released"); System.out.println("Browser Tabs have been switched."); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:faa.cucumber.pages.FaaHomePage.java
public void closeFaaBrowserTabs() { waitABit(2000);/*w w w . java 2 s. c o m*/ Robot robot; try { robot = new Robot(); System.out.println("Close Tab"); robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); System.out.println("Control Key Pressed"); robot.keyPress(java.awt.event.KeyEvent.VK_W); System.out.println("W Key Pressed"); robot.keyRelease(java.awt.event.KeyEvent.VK_W); System.out.println("W Key Released"); System.out.println("Control Key Released"); robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:faa.cucumber.pages.FaaHomePage.java
public void switchToNextTab() { waitABit(2000);/*from ww w . j a v a2 s . c o m*/ Robot robot; try { robot = new Robot(); System.out.println("Switch to the Next Tab"); robot.keyPress(KeyEvent.VK_CONTROL); System.out.println("Control Key Pressed"); robot.keyPress(KeyEvent.VK_PAGE_DOWN); System.out.println("Page Down Key Pressed"); robot.keyRelease(KeyEvent.VK_CONTROL); System.out.println("Control Key Released"); robot.keyRelease(KeyEvent.VK_PAGE_DOWN); System.out.println("Page Down Key Released"); System.out.println("Next Browser Tab has been switched."); } catch (AWTException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:faa.cucumber.pages.FaaHomePage.java
public void switchFaaBrowserTabs() { waitABit(2000);//www. ja va 2 s. c o m Robot robot; try { // //Navigate from Left to Right // Actions action= new Actions(driver); // action.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).build().perform(); robot = new Robot(); System.out.println("Switching Tabs"); robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); System.out.println("Control Key Pressed"); waitABit(1000); robot.keyPress(java.awt.event.KeyEvent.VK_TAB); System.out.println("TAB Key Pressed"); robot.keyRelease(java.awt.event.KeyEvent.VK_TAB); System.out.println("TAB Key Released"); robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); System.out.println("Control Key Released"); // robot.keyPress(java.awt.event.KeyEvent.VK_TAB); // waitABit(1000); // System.out.println("TAB Key Pressed..Second Time" ); // robot.keyPress(java.awt.event.KeyEvent.VK_TAB); // System.out.println("TAB Key Pressed..third Time" ); // waitABit(1000); // System.out.println("Switching Tabs Again" ); // robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); // System.out.println("Control Key Pressed" ); // waitABit(1000); // robot.keyPress(java.awt.event.KeyEvent.VK_TAB); // System.out.println("TAB Key Pressed" ); // waitABit(1000); // robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); // System.out.println("Control Key Released" ); // robot.keyRelease(java.awt.event.KeyEvent.VK_TAB); // System.out.println("TAB Key Released" ); // // // //Navigate from Left to Right // Actions action= new Actions(driver); // action.keyDown(Keys.CONTROL).sendKeys(Keys.TAB).build().perform(); // // System.out.println("Switching Tabs" ); // robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); // System.out.println("Control Key Pressed 2" ); // robot.keyPress(java.awt.event.KeyEvent.VK_TAB); // System.out.println("TAB Key Pressed2 " ); // robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); // System.out.println("Control Key Released 2" ); // robot.keyRelease(java.awt.event.KeyEvent.VK_TAB); // System.out.println("TAB Key Released 2" ); // robot.keyPress(java.awt.event.KeyEvent.VK_CONTROL); // System.out.println("Control Key Pressed" ); // robot.keyPress(java.awt.event.KeyEvent.VK_W); // System.out.println("W Key Pressed" ); // robot.keyRelease(java.awt.event.KeyEvent.VK_CONTROL); // System.out.println("Control Key Released" ); // robot.keyRelease(java.awt.event.KeyEvent.VK_W); // System.out.println("W Key Released" ); } catch (AWTException e) { System.out.println("Error has occured when attempting to Switch Browser Tabs!!"); e.printStackTrace(); } }
From source file:com.chtr.tmoauto.webui.CommonFunctions.java
@Override public void typeUsingRobot(String locator, String value) { WebElement we = findElement(locator); // try to click otherwise ignore if it fails try {//from w w w . j av a 2 s.c om we.click(); } catch (Exception e) { } ClipboardOwner clipboardOwner = new ClipboardOwner() { @Override public void lostOwnership(Clipboard clipboard, Transferable contents) { } }; Robot robot; try { robot = new Robot(); try { we.sendKeys(value); } catch (Exception e) { Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); StringSelection stringSelection = new StringSelection(value); clipboard.setContents(stringSelection, clipboardOwner); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); } } catch (AWTException e1) { e1.printStackTrace(); } }