Example usage for java.awt.event KeyEvent VK_CONTROL

List of usage examples for java.awt.event KeyEvent VK_CONTROL

Introduction

In this page you can find the example usage for java.awt.event KeyEvent VK_CONTROL.

Prototype

int VK_CONTROL

To view the source code for java.awt.event KeyEvent VK_CONTROL.

Click Source Link

Document

Constant for the CONTROL virtual key.

Usage

From source file:com.netease.dagger.BrowserEmulator.java

/**
 * javascript executer which must contains one object to be affected
 * /*  www. j ava 2  s  .com*/
 * @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.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 ww  . j  a  v  a2s.c  o m
        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();
    }
}

From source file:com.sshtools.sshterm.emulation.TerminalEmulation.java

public void keyPressed(int keyCode, char keyChar, int modifiers) {
    if (debug > 0) {
        System.out.println("keyPressed(" + keyCode + "," + keyChar + "," + modifiers);
    }/*from w w  w.  ja v  a2s .  c o m*/
    boolean control = (modifiers & VDUInput.KEY_CONTROL) != 0;
    boolean shift = (modifiers & VDUInput.KEY_SHIFT) != 0;
    boolean alt = (modifiers & VDUInput.KEY_ALT) != 0;
    int xind;
    String[] fmap;
    xind = 0;
    fmap = FunctionKey;
    if (shift) {
        fmap = FunctionKeyShift;
        xind = 1;
    }
    if (control) {
        fmap = FunctionKeyCtrl;
        xind = 2;
    }
    if (alt) {
        fmap = FunctionKeyAlt;
        xind = 3;
    }
    switch (keyCode) {
    case KeyEvent.VK_PAUSE:
        if (shift || control) {
            sendTelnetCommand((byte) 243);
        }

        // BREAK
        break;
    case KeyEvent.VK_ESCAPE:
        writeSpecial(Escape[xind]);
        break;
    case KeyEvent.VK_F1:
        writeSpecial(fmap[1]);
        break;
    case KeyEvent.VK_F2:
        writeSpecial(fmap[2]);
        break;
    case KeyEvent.VK_F3:
        writeSpecial(fmap[3]);
        break;
    case KeyEvent.VK_F4:
        writeSpecial(fmap[4]);
        break;
    case KeyEvent.VK_F5:
        writeSpecial(fmap[5]);
        break;
    case KeyEvent.VK_F6:
        writeSpecial(fmap[6]);
        break;
    case KeyEvent.VK_F7:
        writeSpecial(fmap[7]);
        break;
    case KeyEvent.VK_F8:
        writeSpecial(fmap[8]);
        break;
    case KeyEvent.VK_F9:
        writeSpecial(fmap[9]);
        break;
    case KeyEvent.VK_F10:
        writeSpecial(fmap[10]);
        break;
    case KeyEvent.VK_F11:
        writeSpecial(fmap[11]);
        break;
    case KeyEvent.VK_F12:
        writeSpecial(fmap[12]);
        break;
    case KeyEvent.VK_UP:
        writeSpecial(KeyUp[xind]);
        break;
    case KeyEvent.VK_DOWN:
        writeSpecial(KeyDown[xind]);
        break;
    case KeyEvent.VK_LEFT:
        writeSpecial(KeyLeft[xind]);
        break;
    case KeyEvent.VK_RIGHT:
        writeSpecial(KeyRight[xind]);
        break;
    case KeyEvent.VK_PAGE_DOWN:
        writeSpecial(NextScn[xind]);
        break;
    case KeyEvent.VK_PAGE_UP:
        writeSpecial(PrevScn[xind]);
        break;
    case KeyEvent.VK_INSERT:
        writeSpecial(Insert[xind]);
        break;
    case KeyEvent.VK_DELETE:
        writeSpecial(Remove[xind]);
        break;
    case KeyEvent.VK_BACK_SPACE:
        writeSpecial(BackSpace[xind]);
        if (localecho) {
            if (BackSpace[xind] == "\b" || BackSpace[xind] == "\u007f") {
                putString("\b \b");
                // make the last char 'deleted'
            } else {
                putString(BackSpace[xind]);
                // echo it
            }
        }
        break;
    case KeyEvent.VK_HOME:
        writeSpecial(KeyHome[xind]);
        break;
    case KeyEvent.VK_END:
        writeSpecial(KeyEnd[xind]);
        break;
    case KeyEvent.VK_NUM_LOCK:
        if (vms && control) {
            writeSpecial(PF1);
        }
        if (!control) {
            numlock = !numlock;
        }
        break;
    case KeyEvent.VK_CAPS_LOCK:
        capslock = !capslock;
        return;
    case KeyEvent.VK_SHIFT:
    case KeyEvent.VK_CONTROL:
    case KeyEvent.VK_ALT:
        return;
    default:
        break;
    }
}

From source file:de.codesourcery.jasm16.ide.ui.views.SourceCodeView.java

protected final void setupKeyBindings(final JTextPane editor) {
    // 'Save' action 
    addKeyBinding(editor, KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK), new AbstractAction() {
        @Override/*  w w w .  j a v a 2 s .c om*/
        public void actionPerformed(ActionEvent e) {
            saveCurrentFile();
        }
    });

    // 'Underline text when pressing CTRL while hovering over an identifier' 
    editorPane.addKeyListener(new KeyAdapter() {
        private boolean isControlKey(KeyEvent e) {
            return e.getKeyCode() == KeyEvent.VK_CONTROL;
        }

        public void keyPressed(KeyEvent e) {
            if (isControlKey(e)) {
                final Point ptr = getMouseLocation();
                if (ptr != null) {
                    maybeUnderlineIdentifierAt(ptr);
                }
            }
        }

        public void keyReleased(KeyEvent e) {
            if (isControlKey(e)) {
                clearUnderlineHighlight();
            }
        };
    });

    // "Undo" action
    addKeyBinding(editor, KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK), undoAction);

    addKeyBinding(editor, KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK), redoAction);

    // 'Search' action 
    addKeyBinding(editor, KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK), new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            showSearchDialog();
        }
    });

    setupKeyBindingsHook(editor);
}

From source file:faa.cucumber.pages.FaaHomePage.java

public void switchPressControlTab() {
    waitABit(2000);//from  w  w  w.  j a  va 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();
    }
}

From source file:faa.cucumber.pages.FaaHomePage.java

public void switchReleaseControlTab() {
    waitABit(2000);/*www.j  av  a 2 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 switchFaaBrowserTabs() {
    waitABit(2000);/*from   ww w  . j  av a  2s  .  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.virtusa.isq.rft.runtime.RFTCommandBase.java

/**
 * Get the selected text in webpage to the clipboard and compare the value
 * with the given input.//  www .jav  a2 s .co  m
 * 
 * @param value
 *            the value
 * @throws Exception
 *             the exception
 */

private void fireEventVerifyValue(final String value) throws Exception {

    String clipBoardText = "";
    Robot robot = new Robot();

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_C);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    Utils.pause(retryInterval);
    Transferable trans = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);

    try {
        if (trans != null) {
            clipBoardText = (String) trans.getTransferData(DataFlavor.stringFlavor);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (clipBoardText.equals(value)) {

        reportResults(ReportLogger.ReportLevel.SUCCESS, "Fire Event", "Success",
                "Verify value passed. Value : " + value);

    } else {

        reportResults(true, ReportLogger.ReportLevel.FAILURE, "Fire Event", "Error",
                "Verify value match expected. ::: " + "Expected value : " + value + " Actual value : "
                        + clipBoardText);
    }
}

From source file:faa.cucumber.pages.FaaHomePage.java

public void switchBrowserTabs() {
    waitABit(2000);/*from   w  w  w  .  j a  va 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:com.virtusa.isq.rft.runtime.RFTCommandBase.java

/**
 * Fires a set of java robot key events into the webpage.
 * /*www.j a v a 2 s  . c  o  m*/
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireKeyEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = new Robot();
    for (String fullCommand : commandSet) {
        Utils.pause(retryInterval / 2);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            StringSelection stringSelection = new StringSelection(input);
            clipboard.setContents(stringSelection, null);

            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);

        } else if ("Key".equalsIgnoreCase(command)) {

            type(input);
        } else if ("wait".equalsIgnoreCase(command)) {

            Utils.pause(Integer.parseInt(input));
        } else {
            throw new Exception("Command " + command);
        }
    }
}