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:faa.cucumber.pages.FaaHomePage.java

public void switchToNextTab() {
    waitABit(2000);//from  w  w w.ja v  a 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 closeFaaBrowserTabs() {
    waitABit(2000);//from   ww w .ja v  a2s  .  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:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Force handle popup./*from  ww  w .  j a  va2  s  .  co m*/
 * 
 * @param robot
 *            the robot
 * @param inputString
 *            the input string
 */
public final void forceHandlePopup(final Robot robot, final String inputString) {
    String[] commandSet = inputString.split("\\|");

    for (String fullCommand : commandSet) {
        sleep(retryInterval);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {

            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)) {

            super.sleep(Integer.parseInt(input));
        }

    }
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Get the selected text in webpage to the clipboard and compare the value
 * with the given input./*  ww  w.j  ava 2 s .  c  om*/
 * 
 * @param value
 *            the value
 * @throws Exception
 *             the exception
 */

private void fireEventVerifyValue(final String value) throws Exception {

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

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

    sleep(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)) {

        reportresult(true, "FIRE EVENT : VERIFY VALUE " + value + "", "PASSED", "");
    } else {

        reportresult(true, "FIRE EVENT : VERIFY VALUE " + value + "", "FAILED",
                "FIRE EVENT : VERIFY VALUE : value match expected. Actual : " + clipBoardText + " Expected : "
                        + value + "");
        checkTrue(false, true, "FIRE EVENT : VERIFY VALUE : value match expected. Actual : " + clipBoardText
                + " Expected : " + value + "");
    }
}

From source file:com.virtusa.isq.vtaf.runtime.SeleniumTestBase.java

/**
 * Fires a set of java robot key events into the webpage.
 * // w  w w .  j  av a 2  s  .  co m
 * @param commands
 *            the commands
 * @throws Exception
 *             the exception
 */

private void fireKeyEvent(final String commands) throws Exception {

    String[] commandSet = commands.split("\\|");
    Robot robot = getRobot();
    for (String fullCommand : commandSet) {
        sleep(retryInterval / 2);
        int commandIndex = 0;
        int inputIndex = 1;
        String command = fullCommand.split("=")[commandIndex];
        String input = fullCommand.split("=")[inputIndex];
        if ("type".equalsIgnoreCase(command)) {

            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)) {

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

From source file:org.apache.openmeetings.screenshare.job.RemoteJob.java

private String getHighlightedText() {
    try {//from   w w w.  j a v  a2s .  c  o m
        if (SystemUtils.IS_OS_MAC) {
            // Macintosh simulate Copy
            press(157, 67);
        } else {
            // pressing CTRL+C == copy
            press(KeyEvent.VK_CONTROL, KeyEvent.VK_C);
        }
        return getClipboardText();
    } catch (Exception e) {
        log.error("Unexpected exception while getting highlighted text", e);
    }
    return "";
}

From source file:org.apache.openmeetings.screenshare.job.RemoteJob.java

private void paste(String charValue) {
    Clipboard clippy = getDefaultToolkit().getSystemClipboard();
    try {//from  w w w .j ava 2 s . co m
        Transferable transferableText = new StringSelection(charValue);
        clippy.setContents(transferableText, null);

        if (SystemUtils.IS_OS_MAC) {
            // Macintosh simulate Insert
            press(157, 86);
        } else {
            // pressing CTRL+V == insert-mode
            press(KeyEvent.VK_CONTROL, KeyEvent.VK_V);
        }
    } catch (Exception e) {
        log.error("Unexpected exception while pressSpecialSign", e);
    }
}

From source file:org.eclipse.jubula.rc.common.driver.KeyTyper.java

/**
 * @param keyStroke KeyStroke whose modifiers are requested
 * @return a List of KeyCodes (hopefully) realising the ModifierMask contained in the KeyStroke
 *//*from   w ww.ja v  a 2  s .co  m*/
private List modifierKeyCodes(KeyStroke keyStroke) {
    List l = new LinkedList();
    int modifiers = keyStroke.getModifiers();
    // this is jdk 1.3 - code.
    // use ALT_DOWN_MASK instead etc. with jdk 1.4 !
    if ((modifiers & InputEvent.ALT_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_ALT));
    }
    if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_ALT_GRAPH));
    }
    if ((modifiers & InputEvent.CTRL_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_CONTROL));
    }
    if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_SHIFT));
    }
    if ((modifiers & InputEvent.META_MASK) != 0) {
        l.add(new Integer(KeyEvent.VK_META));
    }
    return l;
}

From source file:org.openecomp.sdc.ci.tests.utilities.GeneralUIUtils.java

public static void uploadFileWithJavaRobot(String FilePath, String FileName) throws Exception {
    StringSelection sel = new StringSelection(FilePath + FileName);
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(sel, null);
    Thread.sleep(1000);/*www.  j a v  a 2  s  . com*/
    Robot robot = new Robot();
    robot.delay(1000);

    // Release Enter
    robot.keyRelease(KeyEvent.VK_ENTER);

    // Press CTRL+V
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);

    // Release CTRL+V
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyRelease(KeyEvent.VK_V);
    Thread.sleep(1000);

    // Press Enter
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    Thread.sleep(3000);
}

From source file:org.openmicroscopy.shoola.agents.treeviewer.browser.BrowserUI.java

/** 
 * Helper method to create the trees hosting the display. 
 * /*from   w  w  w . j a v a2 s.c om*/
 * @param exp The logged in experimenter.
 */
private void createTrees(ExperimenterData exp) {
    treeDisplay = new DnDTree(model.getUserID(), TreeViewerAgent.isAdministrator());
    treeDisplay.addPropertyChangeListener(this);
    String key = "meta pressed A";
    if (UIUtilities.isWindowsOS())
        key = "ctrl pressed A";
    KeyStroke ks = KeyStroke.getKeyStroke(key);
    treeDisplay.getInputMap().put(ks, "none");
    treeDisplay.setVisible(true);
    treeDisplay.setRootVisible(false);
    ToolTipManager.sharedInstance().registerComponent(treeDisplay);
    treeDisplay.setCellRenderer(new TreeCellRenderer(model.getUserID()));
    treeDisplay.setShowsRootHandles(true);
    TreeImageSet root = new TreeImageSet("");
    treeDisplay.setModel(new DefaultTreeModel(root));
    if (model.getBrowserType() != Browser.ADMIN_EXPLORER) {
        TreeImageDisplay node = buildTreeNodes(exp);
        if (node != null)
            treeDisplay.collapsePath(new TreePath(node.getPath()));
    }
    //Add Listeners
    //treeDisplay.requestFocus();
    treeDisplay.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            mousePressedTime = e.getWhen();
            rightClickPad = UIUtilities.isMacOS() && SwingUtilities.isLeftMouseButton(e) && e.isControlDown();
            rightClickButton = SwingUtilities.isRightMouseButton(e);
            ctrl = e.isControlDown();
            if (UIUtilities.isMacOS())
                ctrl = e.isMetaDown();
            leftMouseButton = SwingUtilities.isLeftMouseButton(e);
            if (UIUtilities.isMacOS() || UIUtilities.isLinuxOS())
                onClick(e, false);
        }

        public void mouseReleased(MouseEvent e) {
            leftMouseButton = SwingUtilities.isLeftMouseButton(e);
            if (UIUtilities.isWindowsOS())
                onClick(e, true);
        }

        // public void mouseMoved(MouseEvent e) { rollOver(e); }
    });
    treeDisplay.addMouseMotionListener(new MouseMotionAdapter() {

        public void mouseMoved(MouseEvent e) {
            rollOver(e);
        }
    });
    treeDisplay.addTreeExpansionListener(listener);
    selectionListener = new TreeSelectionListener() {

        public void valueChanged(TreeSelectionEvent e) {
            event = e;
            eventHandledTime = System.currentTimeMillis();

            if (delayedHandlingTreeSelection)
                /* mouse click delayed handling until this event occurred */
                handleTreeSelection();

            switch (keyEvent) {
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_UP:
                TreePath[] paths = treeDisplay.getSelectionPaths();
                if (paths != null)
                    controller.onClick(Arrays.asList(paths));
                else
                    controller.onClick(new ArrayList<TreePath>());
                break;
            }
        }
    };
    treeDisplay.addTreeSelectionListener(selectionListener);
    //remove standard behaviour
    treeDisplay.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            ctrl = false;
            switch (e.getKeyCode()) {
            case KeyEvent.VK_ENTER:
                ViewCmd cmd = new ViewCmd(model.getParentModel(), true);
                cmd.execute();
                break;
            case KeyEvent.VK_DELETE:
                switch (model.getState()) {
                case Browser.LOADING_DATA:
                case Browser.LOADING_LEAVES:
                    //case Browser.COUNTING_ITEMS:  
                    break;
                default:
                    model.delete();
                }
                break;
            case KeyEvent.VK_CONTROL:
                if (!UIUtilities.isMacOS())
                    ctrl = true;
                break;
            case KeyEvent.VK_META:
                if (UIUtilities.isMacOS())
                    ctrl = true;
                break;
            case KeyEvent.VK_A:
                if (UIUtilities.isWindowsOS() && e.isControlDown()
                        || !UIUtilities.isWindowsOS() && e.isMetaDown()) {
                    handleMultiSelection();
                }
                break;
            case KeyEvent.VK_DOWN:
            case KeyEvent.VK_UP:
            case KeyEvent.VK_RIGHT:
                keyEvent = e.getKeyCode();
                break;
            case KeyEvent.VK_LEFT:
                TreePath[] paths = treeDisplay.getSelectionPaths();
                TreeImageDisplay node;
                Object o;
                for (int i = 0; i < paths.length; i++) {
                    o = paths[i].getLastPathComponent();
                    if (o instanceof TreeImageDisplay) {
                        node = (TreeImageDisplay) o;
                        if (node.isExpanded())
                            node.setExpanded(false);
                    }
                }
            }
        }

        public void keyReleased(KeyEvent e) {
            ctrl = false;
            keyEvent = -1;
        }

    });
}