Example usage for java.awt.event KeyEvent getKeyModifiersText

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

Introduction

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

Prototype

@Deprecated(since = "9")
public static String getKeyModifiersText(int modifiers) 

Source Link

Document

Returns a String describing the modifier key(s), such as "Shift", or "Ctrl+Shift".

Usage

From source file:Main.java

/**
 * Returns the key stroke representation translated.
 * //from   ww  w  .ja  v a 2 s . c om
 * @param keyStroke The key stroke.
 * @param locale The locale.
 * @return The key stroke representation translated.
 */
public static String translate(KeyStroke keyStroke, Locale locale) {
    //      String[] tokens = StringUtils.parse(StringUtils.toString(keyStroke), " ");
    //      if (tokens.length > 1) {
    //         Arrays.sort(tokens, 0, tokens.length - 1);
    //      }
    //      StringBuilder b = new StringBuilder();
    //      for (int i = 0; i < tokens.length; i++) {
    //         String token = tokens[i];
    //         String key = "key_" + token;
    //         String translated = TextServer.getString(key, locale);
    //         if (translated.equals(TextServer.notFoundKey(key))) {
    //            translated = token;
    //         }
    //         if (i > 0) {
    //            b.append("+");
    //         }
    //         b.append(translated);
    //      }
    //      return b.toString();
    String acceleratorText = "";
    if (keyStroke != null) {
        int modifiers = keyStroke.getModifiers();
        if (modifiers > 0) {
            acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
            acceleratorText += "+";
        }
        acceleratorText += KeyEvent.getKeyText(keyStroke.getKeyCode());
    }
    return acceleratorText;
}

From source file:com.mirth.connect.client.ui.components.KeyStrokeTextField.java

private void updateKeyStroke() {
    StringBuilder builder = new StringBuilder();

    for (int mask : modifierMasks) {
        if ((modifiers & mask) > 0) {
            if (builder.length() > 0) {
                builder.append('+');
            }/*from   w w  w .java2 s .  c om*/
            builder.append(KeyEvent.getKeyModifiersText(mask));
        }
    }

    if (keyCode != null) {
        if (builder.length() > 0) {
            builder.append('-');
        }
        builder.append(KeyEvent.getKeyText(keyCode));
    }

    setText(builder.toString());
}

From source file:EventTestPane.java

/**
 * Display keyboard events./*from   w w  w .j ava2s. co  m*/
 * 
 * Note that there are three distinct types of key events, and that key
 * events are reported by key code and/or Unicode character. KEY_PRESSED and
 * KEY_RELEASED events are generated for all key strokes. KEY_TYPED events
 * are only generated when a key stroke produces a Unicode character; these
 * events do not report a key code. If isActionKey() returns true, then the
 * key event reports only a key code, because the key that was pressed or
 * released (such as a function key) has no corresponding Unicode character.
 * Key codes can be interpreted by using the many VK_ constants defined by
 * the KeyEvent class, or they can be converted to strings using the static
 * getKeyText() method as we do here.
 */
public void processKeyEvent(KeyEvent e) {
    String eventtype, modifiers, code, character;
    switch (e.getID()) {
    case KeyEvent.KEY_PRESSED:
        eventtype = "KEY_PRESSED";
        break;
    case KeyEvent.KEY_RELEASED:
        eventtype = "KEY_RELEASED";
        break;
    case KeyEvent.KEY_TYPED:
        eventtype = "KEY_TYPED";
        break;
    default:
        eventtype = "UNKNOWN";
    }

    // Convert the list of modifier keys to a string
    modifiers = KeyEvent.getKeyModifiersText(e.getModifiers());

    // Get string and numeric versions of the key code, if any.
    if (e.getID() == KeyEvent.KEY_TYPED)
        code = "";
    else
        code = "Code=" + KeyEvent.getKeyText(e.getKeyCode()) + " (" + e.getKeyCode() + ")";

    // Get string and numeric versions of the Unicode character, if any.
    if (e.isActionKey())
        character = "";
    else
        character = "Character=" + e.getKeyChar() + " (Unicode=" + ((int) e.getKeyChar()) + ")";

    // Display it all.
    showLine(eventtype + ": " + modifiers + " " + code + " " + character);
}

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

/**
 * Types the given keystroke.//  w w w.  j  a  v a  2s .c  o m
 * If any of the intercepting and event matching arguments are 
 * <code>null</code>, this method will not wait for event confirmation. It 
 * will simply assume that the events were received correctly. Otherwise,
 * this method will use the given interceptor and event matcher arguments to
 * handle event confirmation.
 * 
 * @param keyStroke The key stroke. May not be null.
 * @param interceptor The interceptor that will be used to wait for event
 *                    confirmation.
 * @param keyDownMatcher The event matcher to be used for key press event
 *                       confirmation.
 * @param keyUpMatcher The event matcher to be used for key release event
 *                     confirmation.
 */
public void type(KeyStroke keyStroke, IRobotEventInterceptor interceptor, IEventMatcher keyDownMatcher,
        IEventMatcher keyUpMatcher) {

    try {
        Validate.notNull(keyStroke);
        boolean waitForConfirm = interceptor != null && keyDownMatcher != null && keyUpMatcher != null;
        InterceptorOptions options = new InterceptorOptions(new long[] { AWTEvent.KEY_EVENT_MASK });
        List keycodes = modifierKeyCodes(keyStroke);
        keycodes.add(new Integer(keyStroke.getKeyCode()));
        if (log.isDebugEnabled()) {
            String keyModifierText = KeyEvent.getKeyModifiersText(keyStroke.getModifiers());
            String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());
            log.debug("Key stroke: " + keyStroke); //$NON-NLS-1$
            log.debug("Modifiers, Key: " + keyModifierText + ", " + keyText); //$NON-NLS-1$//$NON-NLS-2$
            log.debug("number of keycodes: " + keycodes.size()); //$NON-NLS-1$
        }
        m_robot.setAutoWaitForIdle(true);

        // FIXME Hack for MS Windows for keys that also appear on the numpad.
        //       Turns NumLock off. Does nothing if locking key functionality
        //       isn't implemented for the operating system.
        boolean isNumLockToggled = hackWindowsNumpadKeys1(keyStroke.getKeyCode());

        // first press all keys, then release all keys, but
        // avoid to press and release any key twice (even if perhaps alt
        // and meta should have the same keycode(??)
        Set alreadyDown = new HashSet();
        ListIterator i = keycodes.listIterator();
        try {
            while (i.hasNext()) {
                Integer keycode = (Integer) i.next();
                if (log.isDebugEnabled()) {
                    log.debug("trying to press: " + keycode); //$NON-NLS-1$
                }
                if (!alreadyDown.contains(keycode)) {
                    IRobotEventConfirmer confirmer = null;
                    if (waitForConfirm) {
                        confirmer = interceptor.intercept(options);
                    }
                    if (log.isDebugEnabled()) {
                        log.debug("pressing: " + keycode); //$NON-NLS-1$
                    }
                    alreadyDown.add(keycode);
                    m_robot.keyPress(keycode.intValue());
                    if (waitForConfirm) {
                        confirmer.waitToConfirm(null, keyDownMatcher);
                    }
                }
            }
        } finally {
            releaseKeys(options, alreadyDown, i, interceptor, keyUpMatcher);
            // FIXME Hack for MS Windows for keys that also appear on the numpad.
            //       Turns NumLock back on, if necessary.
            if (isNumLockToggled) {
                hackWindowsNumpadKeys2();
            }
        }
    } catch (IllegalArgumentException e) {
        throw new RobotException(e);
    }
}

From source file:org.underworldlabs.swing.plaf.base.AcceleratorToolTipUI.java

private String getAcceleratorString(JToolTip tip) {

    String acceleratorString = null;
    Action action = ((AbstractButton) tip.getComponent()).getAction();

    if (action != null) {

        KeyStroke keyStroke = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);
        if (keyStroke != null) {

            int mod = keyStroke.getModifiers();
            acceleratorString = KeyEvent.getKeyModifiersText(mod);

            if (!MiscUtils.isNull(acceleratorString)) {

                acceleratorString += DELIMITER;
            }/*from  w  w w .  j a  va 2  s.  co  m*/

            String keyText = KeyEvent.getKeyText(keyStroke.getKeyCode());
            if (!MiscUtils.isNull(keyText)) {

                acceleratorString += keyText;
            }

        }

    }

    return acceleratorString;
}

From source file:uk.chromis.pos.forms.JRootApp.java

private void m_txtKeysKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_m_txtKeysKeyTyped

    if (evt.getModifiers() != 0) {
        String keys = evt.getKeyModifiersText(evt.getModifiers()) + "+" + evt.getKeyChar();
        if ((keys.equals("Alt+Shift+P")) || (keys.equals("Alt+Shift+p"))) {
            superUserLogin();//from ww w .j ava2  s  .  co  m
        }
    }
    m_txtKeys.setText("0");
    processKey(evt.getKeyChar());

}