FileDocCategorySizeDatePackage
KeyEvent.javaAPI DocAndroid 1.5 API19328Wed May 06 22:41:54 BST 2009java.awt.event

KeyEvent

public class KeyEvent extends InputEvent
This class is not supported in Android 1.0. It is merely provided to maintain interface compatibility with desktop Java implementations.
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
public static final int
KEY_FIRST
public static final int
KEY_LAST
public static final int
KEY_TYPED
public static final int
KEY_PRESSED
public static final int
KEY_RELEASED
public static final int
VK_ENTER
public static final int
VK_BACK_SPACE
public static final int
VK_TAB
public static final int
VK_CANCEL
public static final int
VK_CLEAR
public static final int
VK_SHIFT
public static final int
VK_CONTROL
public static final int
VK_ALT
public static final int
VK_PAUSE
public static final int
VK_CAPS_LOCK
public static final int
VK_ESCAPE
public static final int
VK_SPACE
public static final int
VK_PAGE_UP
public static final int
VK_PAGE_DOWN
public static final int
VK_END
public static final int
VK_HOME
public static final int
VK_LEFT
public static final int
VK_UP
public static final int
VK_RIGHT
public static final int
VK_DOWN
public static final int
VK_COMMA
public static final int
VK_MINUS
public static final int
VK_PERIOD
public static final int
VK_SLASH
public static final int
VK_0
public static final int
VK_1
public static final int
VK_2
public static final int
VK_3
public static final int
VK_4
public static final int
VK_5
public static final int
VK_6
public static final int
VK_7
public static final int
VK_8
public static final int
VK_9
public static final int
VK_SEMICOLON
public static final int
VK_EQUALS
public static final int
VK_A
public static final int
VK_B
public static final int
VK_C
public static final int
VK_D
public static final int
VK_E
public static final int
VK_F
public static final int
VK_G
public static final int
VK_H
public static final int
VK_I
public static final int
VK_J
public static final int
VK_K
public static final int
VK_L
public static final int
VK_M
public static final int
VK_N
public static final int
VK_O
public static final int
VK_P
public static final int
VK_Q
public static final int
VK_R
public static final int
VK_S
public static final int
VK_T
public static final int
VK_U
public static final int
VK_V
public static final int
VK_W
public static final int
VK_X
public static final int
VK_Y
public static final int
VK_Z
public static final int
VK_OPEN_BRACKET
public static final int
VK_BACK_SLASH
public static final int
VK_CLOSE_BRACKET
public static final int
VK_NUMPAD0
public static final int
VK_NUMPAD1
public static final int
VK_NUMPAD2
public static final int
VK_NUMPAD3
public static final int
VK_NUMPAD4
public static final int
VK_NUMPAD5
public static final int
VK_NUMPAD6
public static final int
VK_NUMPAD7
public static final int
VK_NUMPAD8
public static final int
VK_NUMPAD9
public static final int
VK_MULTIPLY
public static final int
VK_ADD
public static final int
VK_SEPARATER
public static final int
VK_SEPARATOR
public static final int
VK_SUBTRACT
public static final int
VK_DECIMAL
public static final int
VK_DIVIDE
public static final int
VK_DELETE
public static final int
VK_NUM_LOCK
public static final int
VK_SCROLL_LOCK
public static final int
VK_F1
public static final int
VK_F2
public static final int
VK_F3
public static final int
VK_F4
public static final int
VK_F5
public static final int
VK_F6
public static final int
VK_F7
public static final int
VK_F8
public static final int
VK_F9
public static final int
VK_F10
public static final int
VK_F11
public static final int
VK_F12
public static final int
VK_F13
public static final int
VK_F14
public static final int
VK_F15
public static final int
VK_F16
public static final int
VK_F17
public static final int
VK_F18
public static final int
VK_F19
public static final int
VK_F20
public static final int
VK_F21
public static final int
VK_F22
public static final int
VK_F23
public static final int
VK_F24
public static final int
VK_PRINTSCREEN
public static final int
VK_INSERT
public static final int
VK_HELP
public static final int
VK_META
public static final int
VK_BACK_QUOTE
public static final int
VK_QUOTE
public static final int
VK_KP_UP
public static final int
VK_KP_DOWN
public static final int
VK_KP_LEFT
public static final int
VK_KP_RIGHT
public static final int
VK_DEAD_GRAVE
public static final int
VK_DEAD_ACUTE
public static final int
VK_DEAD_CIRCUMFLEX
public static final int
VK_DEAD_TILDE
public static final int
VK_DEAD_MACRON
public static final int
VK_DEAD_BREVE
public static final int
VK_DEAD_ABOVEDOT
public static final int
VK_DEAD_DIAERESIS
public static final int
VK_DEAD_ABOVERING
public static final int
VK_DEAD_DOUBLEACUTE
public static final int
VK_DEAD_CARON
public static final int
VK_DEAD_CEDILLA
public static final int
VK_DEAD_OGONEK
public static final int
VK_DEAD_IOTA
public static final int
VK_DEAD_VOICED_SOUND
public static final int
VK_DEAD_SEMIVOICED_SOUND
public static final int
VK_AMPERSAND
public static final int
VK_ASTERISK
public static final int
VK_QUOTEDBL
public static final int
VK_LESS
public static final int
VK_GREATER
public static final int
VK_BRACELEFT
public static final int
VK_BRACERIGHT
public static final int
VK_AT
public static final int
VK_COLON
public static final int
VK_CIRCUMFLEX
public static final int
VK_DOLLAR
public static final int
VK_EURO_SIGN
public static final int
VK_EXCLAMATION_MARK
public static final int
VK_INVERTED_EXCLAMATION_MARK
public static final int
VK_LEFT_PARENTHESIS
public static final int
VK_NUMBER_SIGN
public static final int
VK_PLUS
public static final int
VK_RIGHT_PARENTHESIS
public static final int
VK_UNDERSCORE
public static final int
VK_FINAL
public static final int
VK_WINDOWS
public static final int
VK_CONTEXT_MENU
public static final int
VK_CONVERT
public static final int
VK_NONCONVERT
public static final int
VK_ACCEPT
public static final int
VK_MODECHANGE
public static final int
VK_KANA
public static final int
VK_KANJI
public static final int
VK_ALPHANUMERIC
public static final int
VK_KATAKANA
public static final int
VK_HIRAGANA
public static final int
VK_FULL_WIDTH
public static final int
VK_HALF_WIDTH
public static final int
VK_ROMAN_CHARACTERS
public static final int
VK_ALL_CANDIDATES
public static final int
VK_PREVIOUS_CANDIDATE
public static final int
VK_CODE_INPUT
public static final int
VK_JAPANESE_KATAKANA
public static final int
VK_JAPANESE_HIRAGANA
public static final int
VK_JAPANESE_ROMAN
public static final int
VK_KANA_LOCK
public static final int
VK_INPUT_METHOD_ON_OFF
public static final int
VK_CUT
public static final int
VK_COPY
public static final int
VK_PASTE
public static final int
VK_UNDO
public static final int
VK_AGAIN
public static final int
VK_FIND
public static final int
VK_PROPS
public static final int
VK_STOP
public static final int
VK_COMPOSE
public static final int
VK_ALT_GRAPH
public static final int
VK_BEGIN
public static final int
VK_UNDEFINED
public static final char
CHAR_UNDEFINED
public static final int
KEY_LOCATION_UNKNOWN
public static final int
KEY_LOCATION_STANDARD
public static final int
KEY_LOCATION_LEFT
public static final int
KEY_LOCATION_RIGHT
public static final int
KEY_LOCATION_NUMPAD
private int
keyCode
private char
keyChar
private int
keyLocation
Constructors Summary
public KeyEvent(Component src, int id, long when, int modifiers, int keyCode)

        this(src, id, when, modifiers, keyCode,
                (keyCode > (2 << 7) - 1) ? CHAR_UNDEFINED : (char) keyCode);
    
public KeyEvent(Component src, int id, long when, int modifiers, int keyCode, char keyChar)

        this(src, id, when, modifiers, keyCode, keyChar, KEY_LOCATION_UNKNOWN);
    
public KeyEvent(Component src, int id, long when, int modifiers, int keyCode, char keyChar, int keyLocation)

        super(src, id, when, modifiers);

        if (id == KEY_TYPED) {
            if (keyCode != VK_UNDEFINED) {
                // awt.191=Invalid keyCode for KEY_TYPED event, must be VK_UNDEFINED
                throw new IllegalArgumentException(Messages.getString("awt.191")); //$NON-NLS-1$
            }
            if (keyChar == CHAR_UNDEFINED) {
                // awt.192=Invalid keyChar for KEY_TYPED event, can't be CHAR_UNDEFINED
                throw new IllegalArgumentException(Messages.getString("awt.192")); //$NON-NLS-1$
            }
        }
        
        if ((keyLocation < KEY_LOCATION_UNKNOWN)
                || (keyLocation > KEY_LOCATION_NUMPAD)) {
            // awt.297=Invalid keyLocation
            throw new IllegalArgumentException(Messages.getString("awt.297")); //$NON-NLS-1$
        }

        this.keyChar = keyChar;
        this.keyLocation = keyLocation;
        this.keyCode = keyCode;
    
Methods Summary
private static java.lang.StringgetDefaultName(java.lang.String[] rawName)

        String name = ""; //$NON-NLS-1$

        for (int i = 0; true; i++) {
            String part = rawName[i];

            name += new String(new char[] {part.charAt(0)}).toUpperCase() +
                    part.substring(1).toLowerCase();

            if (i == (rawName.length - 1)) {
                break;
            }
            name += " "; //$NON-NLS-1$
        }

        return name;
    
public chargetKeyChar()

        return keyChar;
    
public intgetKeyCode()

        return keyCode;
    
public intgetKeyLocation()

        return keyLocation;
    
static java.lang.StringgetKeyModifiersExText(int modifiersEx)

        String text = ""; //$NON-NLS-1$

        if ((modifiersEx & InputEvent.META_DOWN_MASK) != 0) {
            text += Toolkit.getProperty("AWT.meta", "Meta"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if ((modifiersEx & InputEvent.CTRL_DOWN_MASK) != 0) {
            text += ((text.length() > 0) ? "+" : "") + //$NON-NLS-1$ //$NON-NLS-2$
                    Toolkit.getProperty("AWT.control", "Ctrl"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if ((modifiersEx & InputEvent.ALT_DOWN_MASK) != 0) {
            text += ((text.length() > 0) ? "+" : "") + //$NON-NLS-1$ //$NON-NLS-2$
                    Toolkit.getProperty("AWT.alt", "Alt"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if ((modifiersEx & InputEvent.SHIFT_DOWN_MASK) != 0) {
            text += ((text.length() > 0) ? "+" : "") + //$NON-NLS-1$ //$NON-NLS-2$
                    Toolkit.getProperty("AWT.shift", "Shift"); //$NON-NLS-1$ //$NON-NLS-2$
        }
        if ((modifiersEx & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
            text += ((text.length() > 0) ? "+" : "") + //$NON-NLS-1$ //$NON-NLS-2$
                    Toolkit.getProperty("AWT.altGraph", "Alt Graph"); //$NON-NLS-1$ //$NON-NLS-2$
        }

        return text;
    
public static java.lang.StringgetKeyModifiersText(int modifiers)


         
        return getKeyModifiersExText(extractExFlags(modifiers));
    
public static java.lang.StringgetKeyText(int keyCode)

        String[] rawName = getPublicStaticFinalIntFieldName(keyCode); //$NON-NLS-1$

        if ((rawName == null) || (rawName.length == 0)) {
            return ("Unknown keyCode: " + (keyCode >= 0 ? "0x" : "-0x") + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    Integer.toHexString(Math.abs(keyCode)));
        }

        String propertyName = getPropertyName(rawName);
        String defaultName = getDefaultName(rawName);

        return Toolkit.getProperty(propertyName, defaultName);
    
private static java.lang.StringgetPropertyName(java.lang.String[] rawName)

        String name = rawName[0].toLowerCase();

        for (int i = 1; i < rawName.length; i++) {
            String part = rawName[i];

            name += new String(new char[] {part.charAt(0)}).toUpperCase() +
                    part.substring(1).toLowerCase();
        }

        return ("AWT." + name); //$NON-NLS-1$
    
private static java.lang.String[]getPublicStaticFinalIntFieldName(int value)

        Field[] allFields = KeyEvent.class.getDeclaredFields();

        try {
            for (Field field : allFields) {
                Class<?> ssalc = field.getType();
                int modifiers = field.getModifiers();

                if (ssalc.isPrimitive() && ssalc.getName().equals("int") && //$NON-NLS-1$
                        Modifier.isFinal(modifiers) && Modifier.isPublic(modifiers) &&
                        Modifier.isStatic(modifiers))
                {
                    if (field.getInt(null) == value){
                        final String name = field.getName();
                        final int prefixLength = name.indexOf("_") + 1;
                        return name.substring(prefixLength).split("_"); //$NON-NLS-1$
                    }
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

        return null;
    
public booleanisActionKey()

        return ((keyChar == CHAR_UNDEFINED) && (keyCode != VK_UNDEFINED) &&
                !((keyCode == VK_ALT) || (keyCode == VK_ALT_GRAPH) ||
                    (keyCode == VK_CONTROL) || (keyCode == VK_META) || (keyCode == VK_SHIFT)));
    
public java.lang.StringparamString()

        /*
         * The format is based on 1.5 release behavior
         * which can be revealed by the following code:
         *
         * KeyEvent e = new KeyEvent(new Component() {}, 
         *       KeyEvent.KEY_PRESSED, 0, 
         *       KeyEvent.CTRL_DOWN_MASK|KeyEvent.SHIFT_DOWN_MASK, 
         *       KeyEvent.VK_A, 'A', KeyEvent.KEY_LOCATION_STANDARD);
         * System.out.println(e);
         */

        String idString = null;
        String locString = null;
        String paramString = null;
        String keyCharString = (keyChar == '\n") ?
                keyCharString = getKeyText(VK_ENTER) : "'" + keyChar + "'"; //$NON-NLS-1$ //$NON-NLS-2$

        switch (id) {
        case KEY_PRESSED:
            idString = "KEY_PRESSED"; //$NON-NLS-1$
            break;
        case KEY_RELEASED:
            idString = "KEY_RELEASED"; //$NON-NLS-1$
            break;
        case KEY_TYPED:
            idString = "KEY_TYPED"; //$NON-NLS-1$
            break;
        default:
            idString = "unknown type"; //$NON-NLS-1$
        }

        switch(keyLocation){
        case KEY_LOCATION_STANDARD:
            locString = "KEY_LOCATION_STANDARD"; //$NON-NLS-1$
            break;
        case KEY_LOCATION_LEFT:
            locString = "KEY_LOCATION_LEFT"; //$NON-NLS-1$
            break;
        case KEY_LOCATION_RIGHT:
            locString = "KEY_LOCATION_RIGHT"; //$NON-NLS-1$
            break;
        case KEY_LOCATION_NUMPAD:
            locString = "KEY_LOCATION_NUMPAD"; //$NON-NLS-1$
            break;
        case KEY_LOCATION_UNKNOWN:
            locString = "KEY_LOCATION_UNKNOWN"; //$NON-NLS-1$
            break;
        default:
            locString = "unknown type"; //$NON-NLS-1$
        }

        paramString = idString + ",keyCode=" + keyCode; //$NON-NLS-1$
        if (isActionKey()) {
            paramString += "," + getKeyText(keyCode); //$NON-NLS-1$
        } else {
            paramString += ",keyChar=" + keyCharString; //$NON-NLS-1$
        }
        if (getModifiersEx() > 0) {
            paramString += ",modifiers=" + getModifiersExText(getModifiersEx()) + //$NON-NLS-1$
                    ",extModifiers=" + getModifiersExText(getModifiersEx()); //$NON-NLS-1$
        }
        paramString += ",keyLocation=" + locString; //$NON-NLS-1$

        return paramString;
    
public voidsetKeyChar(char keyChar)

        this.keyChar = keyChar;
    
public voidsetKeyCode(int keyCode)

        this.keyCode = keyCode;
    
public voidsetModifiers(int modifiers)

        super.setModifiers(modifiers);