Java Code Examples for java.awt.event.KeyEvent#VK_UNDEFINED

The following examples show how to use java.awt.event.KeyEvent#VK_UNDEFINED . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExtendedKeyCodes.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
final public static int getExtendedKeyCodeForChar( int c ) {
    int uc = Character.toUpperCase( c );
    int lc = Character.toLowerCase( c );
    if (regularKeyCodesMap.containsKey( c )) {
        if(regularKeyCodesMap.containsKey(uc)) {
            return regularKeyCodesMap.get( uc );
        }
        return regularKeyCodesMap.get( c );
    }
    uc += 0x01000000;
    lc += 0x01000000;
    if (extendedKeyCodesSet.contains( uc )) {
        return uc;
    }else if (extendedKeyCodesSet.contains( lc )) {
        return lc;
    }
    return KeyEvent.VK_UNDEFINED;
}
 
Example 2
Source File: Robot.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private void checkKeycodeArgument(int keycode) {
    // rather than build a big table or switch statement here, we'll
    // just check that the key isn't VK_UNDEFINED and assume that the
    // peer implementations will throw an exception for other bogus
    // values e.g. -1, 999999
    if (keycode == KeyEvent.VK_UNDEFINED) {
        throw new IllegalArgumentException("Invalid key code");
    }
}
 
Example 3
Source File: AWTKeyStroke.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string that displays and identifies this object's properties.
 * The <code>String</code> returned by this method can be passed
 * as a parameter to <code>getAWTKeyStroke(String)</code> to produce
 * a key stroke equal to this key stroke.
 *
 * @return a String representation of this object
 * @see #getAWTKeyStroke(String)
 */
public String toString() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return getModifiersText(modifiers) + "typed " + keyChar;
    } else {
        return getModifiersText(modifiers) +
            (onKeyRelease ? "released" : "pressed") + " " +
            getVKText(keyCode);
    }
}
 
Example 4
Source File: AWTKeyStroke.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a string that displays and identifies this object's properties.
 * The <code>String</code> returned by this method can be passed
 * as a parameter to <code>getAWTKeyStroke(String)</code> to produce
 * a key stroke equal to this key stroke.
 *
 * @return a String representation of this object
 * @see #getAWTKeyStroke(String)
 */
public String toString() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return getModifiersText(modifiers) + "typed " + keyChar;
    } else {
        return getModifiersText(modifiers) +
            (onKeyRelease ? "released" : "pressed") + " " +
            getVKText(keyCode);
    }
}
 
Example 5
Source File: AWTKeyStroke.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the type of <code>KeyEvent</code> which corresponds to
 * this <code>AWTKeyStroke</code>.
 *
 * @return <code>KeyEvent.KEY_PRESSED</code>,
 *         <code>KeyEvent.KEY_TYPED</code>,
 *         or <code>KeyEvent.KEY_RELEASED</code>
 * @see java.awt.event.KeyEvent
 */
public final int getKeyEventType() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return KeyEvent.KEY_TYPED;
    } else {
        return (onKeyRelease)
            ? KeyEvent.KEY_RELEASED
            : KeyEvent.KEY_PRESSED;
    }
}
 
Example 6
Source File: Robot.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void checkKeycodeArgument(int keycode) {
    // rather than build a big table or switch statement here, we'll
    // just check that the key isn't VK_UNDEFINED and assume that the
    // peer implementations will throw an exception for other bogus
    // values e.g. -1, 999999
    if (keycode == KeyEvent.VK_UNDEFINED) {
        throw new IllegalArgumentException("Invalid key code");
    }
}
 
Example 7
Source File: Robot.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void checkKeycodeArgument(int keycode) {
    // rather than build a big table or switch statement here, we'll
    // just check that the key isn't VK_UNDEFINED and assume that the
    // peer implementations will throw an exception for other bogus
    // values e.g. -1, 999999
    if (keycode == KeyEvent.VK_UNDEFINED) {
        throw new IllegalArgumentException("Invalid key code");
    }
}
 
Example 8
Source File: InputContext.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 9
Source File: MetaData.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 10
Source File: Robot.java    From jdk-1.7-annotated with Apache License 2.0 5 votes vote down vote up
private void checkKeycodeArgument(int keycode) {
    // rather than build a big table or switch statement here, we'll
    // just check that the key isn't VK_UNDEFINED and assume that the
    // peer implementations will throw an exception for other bogus
    // values e.g. -1, 999999
    if (keycode == KeyEvent.VK_UNDEFINED) {
        throw new IllegalArgumentException("Invalid key code");
    }
}
 
Example 11
Source File: Robot.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void checkKeycodeArgument(int keycode) {
    // rather than build a big table or switch statement here, we'll
    // just check that the key isn't VK_UNDEFINED and assume that the
    // peer implementations will throw an exception for other bogus
    // values e.g. -1, 999999
    if (keycode == KeyEvent.VK_UNDEFINED) {
        throw new IllegalArgumentException("Invalid key code");
    }
}
 
Example 12
Source File: OSUtils.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private static CharSequence getKeys(String keysFor, String sKeyStroke) {
    KeyStroke ks = KeyStroke.getKeyStroke(sKeyStroke);
    if (ks == null) {
        throw new WebDriverException("Unable to parse keystroke for " + keysFor + " trying to parse " + sKeyStroke);
    }
    StringBuilder sb = new StringBuilder();
    int modifiers = ks.getModifiers();
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
        sb.append(Keys.CONTROL);
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) == InputEvent.ALT_DOWN_MASK) {
        sb.append(Keys.ALT);
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) == InputEvent.META_DOWN_MASK) {
        sb.append(Keys.META);
    }
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
        sb.append(Keys.SHIFT);
    }
    int keyCode = ks.getKeyCode();
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        sb.append(ks.getKeyChar());
    } else {
        sb.append(keyCharFromKeyCode(keyCode, keysFor));
    }
    sb.append(Keys.NULL);
    return sb.toString();
}
 
Example 13
Source File: AWTKeyStroke.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
/**
 * Returns a string that displays and identifies this object's properties.
 * The <code>String</code> returned by this method can be passed
 * as a parameter to <code>getAWTKeyStroke(String)</code> to produce
 * a key stroke equal to this key stroke.
 *
 * @return a String representation of this object
 * @see #getAWTKeyStroke(String)
 */
public String toString() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return getModifiersText(modifiers) + "typed " + keyChar;
    } else {
        return getModifiersText(modifiers) +
            (onKeyRelease ? "released" : "pressed") + " " +
            getVKText(keyCode);
    }
}
 
Example 14
Source File: AWTKeyStroke.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the type of <code>KeyEvent</code> which corresponds to
 * this <code>AWTKeyStroke</code>.
 *
 * @return <code>KeyEvent.KEY_PRESSED</code>,
 *         <code>KeyEvent.KEY_TYPED</code>,
 *         or <code>KeyEvent.KEY_RELEASED</code>
 * @see java.awt.event.KeyEvent
 */
public final int getKeyEventType() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return KeyEvent.KEY_TYPED;
    } else {
        return (onKeyRelease)
            ? KeyEvent.KEY_RELEASED
            : KeyEvent.KEY_PRESSED;
    }
}
 
Example 15
Source File: DefaultCharBindingMap.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns key + modifiers pair.
 *
 * @param c Symbol code.
 * @return an array of two elements: key code and modifiers mask - a
 * combination of InputEvent MASK fields.
 */
public int[] getKeyAndModifiers(char c) {
    CharKey key = chars.get(c);
    if (key != null) {
        return new int[]{key.key, key.modifiers};
    } else {
        return new int[]{KeyEvent.VK_UNDEFINED, 0};
    }
}
 
Example 16
Source File: AWTKeyStroke.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns the type of <code>KeyEvent</code> which corresponds to
 * this <code>AWTKeyStroke</code>.
 *
 * @return <code>KeyEvent.KEY_PRESSED</code>,
 *         <code>KeyEvent.KEY_TYPED</code>,
 *         or <code>KeyEvent.KEY_RELEASED</code>
 * @see java.awt.event.KeyEvent
 */
public final int getKeyEventType() {
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return KeyEvent.KEY_TYPED;
    } else {
        return (onKeyRelease)
            ? KeyEvent.KEY_RELEASED
            : KeyEvent.KEY_PRESSED;
    }
}
 
Example 17
Source File: MetaData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected Expression instantiate(Object oldInstance, Encoder out) {
    AWTKeyStroke key = (AWTKeyStroke) oldInstance;

    char ch = key.getKeyChar();
    int code = key.getKeyCode();
    int mask = key.getModifiers();
    boolean onKeyRelease = key.isOnKeyRelease();

    Object[] args = null;
    if (ch == KeyEvent.CHAR_UNDEFINED) {
        args = !onKeyRelease
                ? new Object[]{code, mask}
                : new Object[]{code, mask, onKeyRelease};
    } else if (code == KeyEvent.VK_UNDEFINED) {
        if (!onKeyRelease) {
            args = (mask == 0)
                    ? new Object[]{ch}
                    : new Object[]{ch, mask};
        } else if (mask == 0) {
            args = new Object[]{ch, onKeyRelease};
        }
    }
    if (args == null) {
        throw new IllegalStateException("Unsupported KeyStroke: " + key);
    }
    Class<?> type = key.getClass();
    String name = type.getName();
    // get short name of the class
    int index = name.lastIndexOf('.') + 1;
    if (index > 0) {
        name = name.substring(index);
    }
    return new Expression( key, type, "get" + name, args );
}
 
Example 18
Source File: InputMethodContext.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Dispatches committed text to a client component.
 * Called by composition window.
 *
 * @param client The component that the text should get dispatched to.
 * @param text The iterator providing access to the committed
 *        (and possible composed) text.
 * @param committedCharacterCount The number of committed characters in the text.
 */
synchronized void dispatchCommittedText(Component client,
             AttributedCharacterIterator text,
             int committedCharacterCount) {
    // note that the client is not always the current client component -
    // some host input method adapters may dispatch input method events
    // through the Java event queue, and we may have switched clients while
    // the event was in the queue.
    if (committedCharacterCount == 0
            || text.getEndIndex() <= text.getBeginIndex()) {
        return;
    }
    long time = System.currentTimeMillis();
    dispatchingCommittedText = true;
    try {
        InputMethodRequests req = client.getInputMethodRequests();
        if (req != null) {
            // active client -> send text as InputMethodEvent
            int beginIndex = text.getBeginIndex();
            AttributedCharacterIterator toBeCommitted =
                (new AttributedString(text, beginIndex, beginIndex + committedCharacterCount)).getIterator();

            InputMethodEvent inputEvent = new InputMethodEvent(
                    client,
                    InputMethodEvent.INPUT_METHOD_TEXT_CHANGED,
                    toBeCommitted,
                    committedCharacterCount,
                    null, null);

            client.dispatchEvent(inputEvent);
        } else {
            // passive client -> send text as KeyEvents
            char keyChar = text.first();
            while (committedCharacterCount-- > 0 && keyChar != CharacterIterator.DONE) {
                KeyEvent keyEvent = new KeyEvent(client, KeyEvent.KEY_TYPED,
                                             time, 0, KeyEvent.VK_UNDEFINED, keyChar);
                client.dispatchEvent(keyEvent);
                keyChar = text.next();
            }
        }
    } finally {
        dispatchingCommittedText = false;
    }
}
 
Example 19
Source File: StaffApplication.java    From RemoteSupportTool with Apache License 2.0 4 votes vote down vote up
@Override
@SuppressWarnings("Duplicates")
protected synchronized void doHandleKeyPress(KeyEvent e) {
    if (handler == null) return;
    //LOGGER.debug("key pressed: " + e.paramString());

    // Get code of the pressed key.
    // Keypad arrows are translated to regular arrow keys.
    final int keyCode;
    switch (e.getKeyCode()) {
        case KeyEvent.VK_KP_DOWN:
            keyCode = KeyEvent.VK_DOWN;
            break;
        case KeyEvent.VK_KP_LEFT:
            keyCode = KeyEvent.VK_LEFT;
            break;
        case KeyEvent.VK_KP_RIGHT:
            keyCode = KeyEvent.VK_RIGHT;
            break;
        case KeyEvent.VK_KP_UP:
            keyCode = KeyEvent.VK_UP;
            break;
        default:
            keyCode = e.getKeyCode();
            break;
    }

    // Never press undefined key codes.
    if (keyCode == KeyEvent.VK_UNDEFINED) {
        return;
    }

    // Never send caps lock, num lock and scroll lock key.
    if (keyCode == KeyEvent.VK_CAPS_LOCK || keyCode == KeyEvent.VK_NUM_LOCK || keyCode == KeyEvent.VK_SCROLL_LOCK) {
        return;
    }

    // Detect, if a control key was pressed.
    final boolean isControlKey = e.isActionKey() ||
            keyCode == KeyEvent.VK_BACK_SPACE ||
            keyCode == KeyEvent.VK_DELETE ||
            keyCode == KeyEvent.VK_ENTER ||
            keyCode == KeyEvent.VK_SPACE ||
            keyCode == KeyEvent.VK_TAB ||
            keyCode == KeyEvent.VK_ESCAPE ||
            keyCode == KeyEvent.VK_ALT ||
            keyCode == KeyEvent.VK_ALT_GRAPH ||
            keyCode == KeyEvent.VK_CONTROL ||
            keyCode == KeyEvent.VK_SHIFT ||
            keyCode == KeyEvent.VK_META;

    // Press control keys.
    if (isControlKey) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        e.consume();
    }

    // Press other keys, if they are pressed together with a modifier key.
    else if (e.isControlDown() || e.isMetaDown() || windowsKeyDown || (!SystemUtils.IS_OS_MAC && e.isAltDown())) {
        //LOGGER.debug("press key \"{}\" ({})", keyCode, KeyEvent.getKeyText(keyCode));
        handler.sendKeyPress(keyCode);
        if (!pressedKeys.contains(keyCode))
            pressedKeys.add(keyCode);
        e.consume();
    }

    // Remember, that the Windows key was pressed.
    if (keyCode == KeyEvent.VK_WINDOWS) {
        synchronized (Frame.this) {
            windowsKeyDown = true;
        }
    }
}
 
Example 20
Source File: KeyStroke.java    From jdk8u-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an instance of a KeyStroke, specifying whether the key is
 * considered to be activated when it is pressed or released. Unlike all
 * other factory methods in this class, the instances returned by this
 * method are not necessarily cached or shared.
 *
 * @param keyChar the character value for a keyboard key
 * @param onKeyRelease <code>true</code> if this KeyStroke corresponds to a
 *        key release; <code>false</code> otherwise.
 * @return a KeyStroke object for that key
 * @deprecated use getKeyStroke(char)
 */
@Deprecated
public static KeyStroke getKeyStroke(char keyChar, boolean onKeyRelease) {
    return new KeyStroke(keyChar, KeyEvent.VK_UNDEFINED, 0, onKeyRelease);
}