List of usage examples for java.awt Robot keyPress
public synchronized void keyPress(int keycode)
From source file:com.netease.dagger.BrowserEmulator.java
/** * Open new tab in browser/*from w ww. java2 s .c o m*/ */ public void openNewTAB() { pause(stepInterval); try { Robot robot = new Robot(); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_T); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyRelease(KeyEvent.VK_T); } catch (Exception e) { e.printStackTrace(); handleFailure("Failed to open new TAB"); } logger.info("Success to open new TAB"); }
From source file:com.netease.dagger.BrowserEmulator.java
/** * Close previous tab in browser/*w ww . j a v a 2 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
/** * javascript executer which must contains one object to be affected * //from ww w. j ava2 s. c o m * @param js * @param by * */ public void uploadFile(String filepath) { try { //put file path in a clipboard StringSelection strSel = new StringSelection(filepath); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strSel, null); //imitate mouse event ENTER/COPY/PASTE Robot robot = new Robot(); pause(500); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); robot.keyPress(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_V); robot.keyRelease(KeyEvent.VK_CONTROL); robot.keyPress(KeyEvent.VK_ENTER); robot.keyRelease(KeyEvent.VK_ENTER); logger.info("Success to upload file: " + filepath); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.netease.dagger.BrowserEmulator.java
/** * Mimic system-level keyboard event/*w ww . jav a 2s .co m*/ * * @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 wKeyPress() { waitABit(2000);//from www. jav a 2 s . c o m Robot robot; try { robot = new Robot(); System.out.println("Press W Key"); robot.keyPress(java.awt.event.KeyEvent.VK_W); System.out.println("W Key Pressed"); 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 closeFaaBrowserTabs() { waitABit(2000);// www . j a va 2 s .co 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 switchBrowserTabs() { waitABit(2000);//from www . java 2 s .c o m 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 switchFaaBrowserRefresh() { waitABit(2000);//w w w . j a v a 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 switchToNextTab() { waitABit(2000);//from w w w . j a va 2 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 switchPressControlTab() { waitABit(2000);//from w ww. j a v a 2 s . c o m Robot robot; try { robot = new Robot(); System.out.println("Switching Tabs, Keypress Control Tab"); 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(); } }