0001: /*
0002: * @(#)KeyEvent.java 1.13 06/10/10
0003: *
0004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
0005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
0006: *
0007: * This program is free software; you can redistribute it and/or
0008: * modify it under the terms of the GNU General Public License version
0009: * 2 only, as published by the Free Software Foundation.
0010: *
0011: * This program is distributed in the hope that it will be useful, but
0012: * WITHOUT ANY WARRANTY; without even the implied warranty of
0013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0014: * General Public License version 2 for more details (a copy is
0015: * included at /legal/license.txt).
0016: *
0017: * You should have received a copy of the GNU General Public License
0018: * version 2 along with this work; if not, write to the Free Software
0019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020: * 02110-1301 USA
0021: *
0022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
0023: * Clara, CA 95054 or visit www.sun.com if you need additional
0024: * information or have any questions.
0025: *
0026: */
0027:
0028: package java.awt.event;
0029:
0030: import java.awt.Component;
0031: import java.awt.GraphicsEnvironment;
0032: import java.awt.Toolkit;
0033: import java.io.IOException;
0034: import java.io.ObjectInputStream;
0035:
0036: /**
0037: * An event which indicates that a keystroke occurred in a component.
0038: * <P>
0039: * This low-level event is generated by a component object (such as a text
0040: * field) when a key is pressed, released, or typed.
0041: * The event is passed to every <code>KeyListener</code>
0042: * or <code>KeyAdapter</code> object which registered to receive such
0043: * events using the component's <code>addKeyListener</code> method.
0044: * (<code>KeyAdapter</code> objects implement the
0045: * <code>KeyListener</code> interface.) Each such listener object
0046: * gets this <code>KeyEvent</code> when the event occurs.
0047: *
0048: * <p>
0049: * <em>"Key typed" events</em> are higher-level and generally do not depend on
0050: * the platform or keyboard layout. They are generated when a Unicode character
0051: * is entered, and are the preferred way to find out about character input.
0052: * In the simplest case, a key typed event is produced by a single key press
0053: * (e.g., 'a'). Often, however, characters are produced by series of key
0054: * presses (e.g., 'shift' + 'a'), and the mapping from key pressed events to
0055: * key typed events may be many-to-one or many-to-many. Key releases are not
0056: * usually necessary to generate a key typed event, but there are some cases
0057: * where the key typed event is not generated until a key is released (e.g.,
0058: * entering ASCII sequences via the Alt-Numpad method in Windows).
0059: * No key typed events are generated for keys that don't generate Unicode
0060: * characters (e.g., action keys, modifier keys, etc.).
0061: * The getKeyChar method always returns a valid Unicode character or
0062: * CHAR_UNDEFINED.
0063: * For key pressed and key released events, the getKeyCode method returns
0064: * the event's keyCode. For key typed events, the getKeyCode method
0065: * always returns VK_UNDEFINED.
0066: *
0067: * <p>
0068: * <em>"Key pressed" and "key released" events</em> are lower-level and depend
0069: * on the platform and keyboard layout. They are generated whenever a key is
0070: * pressed or released, and are the only way to find out about keys that don't
0071: * generate character input (e.g., action keys, modifier keys, etc.). The key
0072: * being pressed or released is indicated by the getKeyCode method, which returns
0073: * a virtual key code.
0074: *
0075: * <p>
0076: * <em>Virtual key codes</em> are used to report which keyboard key has
0077: * been pressed, rather than a character generated by the combination
0078: * of one or more keystrokes (such as "A", which comes from shift and "a").
0079: *
0080: * <P>
0081: * For example, pressing the Shift key will cause a KEY_PRESSED event
0082: * with a VK_SHIFT keyCode, while pressing the 'a' key will result in
0083: * a VK_A keyCode. After the 'a' key is released, a KEY_RELEASED event
0084: * will be fired with VK_A. Separately, a KEY_TYPED event with a keyChar
0085: * value of 'A' is generated.
0086: *
0087: * <P>
0088: * Notes:
0089: * <ul>
0090: * <li>Key combinations which do not result in Unicode characters, such as action
0091: * keys like F1 and the HELP key, do not generate KEY_TYPED events.
0092: * <li>Not all keyboards or systems are capable of generating all
0093: * virtual key codes. No attempt is made in Java to artificially
0094: * generate these keys.
0095: * <li>Virtual key codes do not identify a physical key, they depend on the
0096: * platform and keyboard layout. For
0097: * example, the key that on a Windows U.S. keyboard layout generates VK_Q,
0098: * generates VK_A on a Windows French keyboard layout.
0099: * <li>In order to support the platform-independent handling of action keys,
0100: * the Java platform uses a few additional virtual key constants for functions
0101: * that would otherwise have to be recognized by interpreting virtual key codes
0102: * and modifiers. For example, for Japanese Windows keyboards, VK_ALL_CANDIDATES
0103: * is returned instead of VK_CONVERT with the ALT modifier.
0104: * </ul>
0105: *
0106: * <P>
0107: * WARNING: Aside from those keys that are defined by the Java language
0108: * (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of the VK_
0109: * constants. Sun reserves the right to change these values as needed
0110: * to accomodate a wider range of keyboards in the future.
0111: *
0112: * @author Carl Quinn
0113: * @author Amy Fowler
0114: * @author Norbert Lindenberg
0115: * @version 1.57 09/21/01
0116: *
0117: * @see KeyAdapter
0118: * @see KeyListener
0119: * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/keylistener.html">Tutorial: Writing a Key Listener</a>
0120: * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
0121: *
0122: * @since 1.1
0123: */
0124: public class KeyEvent extends InputEvent {
0125: /**
0126: * Stores the state of native event dispatching system
0127: * - true, if when the event was created event proxying
0128: * mechanism was active
0129: * - false, if it was inactive
0130: * Used in Component.dispatchEventImpl to correctly dispatch
0131: * events when proxy is active
0132: */
0133: private boolean isProxyActive = false;
0134: /**
0135: * The first number in the range of ids used for key events.
0136: */
0137: public static final int KEY_FIRST = 400;
0138: /**
0139: * The last number in the range of ids used for key events.
0140: */
0141: public static final int KEY_LAST = 402;
0142: /**
0143: * The "key typed" event. This event is generated when a character is
0144: * entered. In the simplest case, it is produced by a single key press.
0145: * Often, however, characters are produced by series of key presses, and
0146: * the mapping from key pressed events to key typed events may be
0147: * many-to-one or many-to-many.
0148: */
0149: public static final int KEY_TYPED = KEY_FIRST;
0150: /**
0151: * The "key pressed" event. This event is generated when a key
0152: * is pushed down.
0153: */
0154: public static final int KEY_PRESSED = 1 + KEY_FIRST; //Event.KEY_PRESS
0155: /**
0156: * The "key released" event. This event is generated when a key
0157: * is let up.
0158: */
0159: public static final int KEY_RELEASED = 2 + KEY_FIRST; //Event.KEY_RELEASE
0160: /* Virtual key codes. */
0161:
0162: public static final int VK_ENTER = '\n';
0163: public static final int VK_BACK_SPACE = '\b';
0164: public static final int VK_TAB = '\t';
0165: public static final int VK_CANCEL = 0x03;
0166: public static final int VK_CLEAR = 0x0C;
0167: public static final int VK_SHIFT = 0x10;
0168: public static final int VK_CONTROL = 0x11;
0169: public static final int VK_ALT = 0x12;
0170: public static final int VK_PAUSE = 0x13;
0171: public static final int VK_CAPS_LOCK = 0x14;
0172: public static final int VK_ESCAPE = 0x1B;
0173: public static final int VK_SPACE = 0x20;
0174: public static final int VK_PAGE_UP = 0x21;
0175: public static final int VK_PAGE_DOWN = 0x22;
0176: public static final int VK_END = 0x23;
0177: public static final int VK_HOME = 0x24;
0178: /**
0179: * Constant for the non-numpad <b>left</b> arrow key.
0180: * @see #VK_KP_LEFT
0181: */
0182: public static final int VK_LEFT = 0x25;
0183: /**
0184: * Constant for the non-numpad <b>up</b> arrow key.
0185: * @see #VK_KP_UP
0186: */
0187: public static final int VK_UP = 0x26;
0188: /**
0189: * Constant for the non-numpad <b>right</b> arrow key.
0190: * @see #VK_KP_RIGHT
0191: */
0192: public static final int VK_RIGHT = 0x27;
0193: /**
0194: * Constant for the non-numpad <b>down</b> arrow key.
0195: * @see #VK_KP_DOWN
0196: */
0197: public static final int VK_DOWN = 0x28;
0198: public static final int VK_COMMA = 0x2C;
0199: /**
0200: * Constant for the "-" key.
0201: * @since 1.2
0202: */
0203: public static final int VK_MINUS = 0x2D;
0204: public static final int VK_PERIOD = 0x2E;
0205: public static final int VK_SLASH = 0x2F;
0206: /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
0207: public static final int VK_0 = 0x30;
0208: public static final int VK_1 = 0x31;
0209: public static final int VK_2 = 0x32;
0210: public static final int VK_3 = 0x33;
0211: public static final int VK_4 = 0x34;
0212: public static final int VK_5 = 0x35;
0213: public static final int VK_6 = 0x36;
0214: public static final int VK_7 = 0x37;
0215: public static final int VK_8 = 0x38;
0216: public static final int VK_9 = 0x39;
0217: public static final int VK_SEMICOLON = 0x3B;
0218: public static final int VK_EQUALS = 0x3D;
0219: /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
0220: public static final int VK_A = 0x41;
0221: public static final int VK_B = 0x42;
0222: public static final int VK_C = 0x43;
0223: public static final int VK_D = 0x44;
0224: public static final int VK_E = 0x45;
0225: public static final int VK_F = 0x46;
0226: public static final int VK_G = 0x47;
0227: public static final int VK_H = 0x48;
0228: public static final int VK_I = 0x49;
0229: public static final int VK_J = 0x4A;
0230: public static final int VK_K = 0x4B;
0231: public static final int VK_L = 0x4C;
0232: public static final int VK_M = 0x4D;
0233: public static final int VK_N = 0x4E;
0234: public static final int VK_O = 0x4F;
0235: public static final int VK_P = 0x50;
0236: public static final int VK_Q = 0x51;
0237: public static final int VK_R = 0x52;
0238: public static final int VK_S = 0x53;
0239: public static final int VK_T = 0x54;
0240: public static final int VK_U = 0x55;
0241: public static final int VK_V = 0x56;
0242: public static final int VK_W = 0x57;
0243: public static final int VK_X = 0x58;
0244: public static final int VK_Y = 0x59;
0245: public static final int VK_Z = 0x5A;
0246: public static final int VK_OPEN_BRACKET = 0x5B;
0247: public static final int VK_BACK_SLASH = 0x5C;
0248: public static final int VK_CLOSE_BRACKET = 0x5D;
0249: public static final int VK_NUMPAD0 = 0x60;
0250: public static final int VK_NUMPAD1 = 0x61;
0251: public static final int VK_NUMPAD2 = 0x62;
0252: public static final int VK_NUMPAD3 = 0x63;
0253: public static final int VK_NUMPAD4 = 0x64;
0254: public static final int VK_NUMPAD5 = 0x65;
0255: public static final int VK_NUMPAD6 = 0x66;
0256: public static final int VK_NUMPAD7 = 0x67;
0257: public static final int VK_NUMPAD8 = 0x68;
0258: public static final int VK_NUMPAD9 = 0x69;
0259: public static final int VK_MULTIPLY = 0x6A;
0260: public static final int VK_ADD = 0x6B;
0261: /**
0262: * This constant is obsolete, and is included only for backwards compatibility.
0263: * @see VK_SEPARATOR
0264: */
0265: public static final int VK_SEPARATER = 0x6C;
0266: /**
0267: * Constant for the Numpad Separator key.
0268: * @since 1.4
0269: */
0270: public static final int VK_SEPARATOR = VK_SEPARATER;
0271: public static final int VK_SUBTRACT = 0x6D;
0272: public static final int VK_DECIMAL = 0x6E;
0273: public static final int VK_DIVIDE = 0x6F;
0274: public static final int VK_DELETE = 0x7F; /* ASCII DEL */
0275: public static final int VK_NUM_LOCK = 0x90;
0276: public static final int VK_SCROLL_LOCK = 0x91;
0277: /** Constant for the F1 function key. */
0278: public static final int VK_F1 = 0x70;
0279: /** Constant for the F2 function key. */
0280: public static final int VK_F2 = 0x71;
0281: /** Constant for the F3 function key. */
0282: public static final int VK_F3 = 0x72;
0283: /** Constant for the F4 function key. */
0284: public static final int VK_F4 = 0x73;
0285: /** Constant for the F5 function key. */
0286: public static final int VK_F5 = 0x74;
0287: /** Constant for the F6 function key. */
0288: public static final int VK_F6 = 0x75;
0289: /** Constant for the F7 function key. */
0290: public static final int VK_F7 = 0x76;
0291: /** Constant for the F8 function key. */
0292: public static final int VK_F8 = 0x77;
0293: /** Constant for the F9 function key. */
0294: public static final int VK_F9 = 0x78;
0295: /** Constant for the F10 function key. */
0296: public static final int VK_F10 = 0x79;
0297: /** Constant for the F11 function key. */
0298: public static final int VK_F11 = 0x7A;
0299: /** Constant for the F12 function key. */
0300: public static final int VK_F12 = 0x7B;
0301: /**
0302: * Constant for the F13 function key.
0303: * @since 1.2
0304: */
0305:
0306: /* F13 - F24 are used on IBM 3270 keyboard; use random range for constants. */
0307: public static final int VK_F13 = 0xF000;
0308: /**
0309: * Constant for the F14 function key.
0310: * @since 1.2
0311: */
0312: public static final int VK_F14 = 0xF001;
0313: /**
0314: * Constant for the F15 function key.
0315: * @since 1.2
0316: */
0317: public static final int VK_F15 = 0xF002;
0318: /**
0319: * Constant for the F16 function key.
0320: * @since 1.2
0321: */
0322: public static final int VK_F16 = 0xF003;
0323: /**
0324: * Constant for the F17 function key.
0325: * @since 1.2
0326: */
0327: public static final int VK_F17 = 0xF004;
0328: /**
0329: * Constant for the F18 function key.
0330: * @since 1.2
0331: */
0332: public static final int VK_F18 = 0xF005;
0333: /**
0334: * Constant for the F19 function key.
0335: * @since 1.2
0336: */
0337: public static final int VK_F19 = 0xF006;
0338: /**
0339: * Constant for the F20 function key.
0340: * @since 1.2
0341: */
0342: public static final int VK_F20 = 0xF007;
0343: /**
0344: * Constant for the F21 function key.
0345: * @since 1.2
0346: */
0347: public static final int VK_F21 = 0xF008;
0348: /**
0349: * Constant for the F22 function key.
0350: * @since 1.2
0351: */
0352: public static final int VK_F22 = 0xF009;
0353: /**
0354: * Constant for the F23 function key.
0355: * @since 1.2
0356: */
0357: public static final int VK_F23 = 0xF00A;
0358: /**
0359: * Constant for the F24 function key.
0360: * @since 1.2
0361: */
0362: public static final int VK_F24 = 0xF00B;
0363: public static final int VK_PRINTSCREEN = 0x9A;
0364: public static final int VK_INSERT = 0x9B;
0365: public static final int VK_HELP = 0x9C;
0366: public static final int VK_META = 0x9D;
0367: public static final int VK_BACK_QUOTE = 0xC0;
0368: public static final int VK_QUOTE = 0xDE;
0369: /**
0370: * Constant for the numeric keypad <b>up</b> arrow key.
0371: * @see #VK_UP
0372: * @since 1.2
0373: */
0374: public static final int VK_KP_UP = 0xE0;
0375: /**
0376: * Constant for the numeric keypad <b>down</b> arrow key.
0377: * @see #VK_DOWN
0378: * @since 1.2
0379: */
0380: public static final int VK_KP_DOWN = 0xE1;
0381: /**
0382: * Constant for the numeric keypad <b>left</b> arrow key.
0383: * @see #VK_LEFT
0384: * @since 1.2
0385: */
0386: public static final int VK_KP_LEFT = 0xE2;
0387: /**
0388: * Constant for the numeric keypad <b>right</b> arrow key.
0389: * @see #VK_RIGHT
0390: * @since 1.2
0391: */
0392: public static final int VK_KP_RIGHT = 0xE3;
0393: /* For European keyboards */
0394:
0395: /** @since 1.2 */
0396: public static final int VK_DEAD_GRAVE = 0x80;
0397: /** @since 1.2 */
0398: public static final int VK_DEAD_ACUTE = 0x81;
0399: /** @since 1.2 */
0400: public static final int VK_DEAD_CIRCUMFLEX = 0x82;
0401: /** @since 1.2 */
0402: public static final int VK_DEAD_TILDE = 0x83;
0403: /** @since 1.2 */
0404: public static final int VK_DEAD_MACRON = 0x84;
0405: /** @since 1.2 */
0406: public static final int VK_DEAD_BREVE = 0x85;
0407: /** @since 1.2 */
0408: public static final int VK_DEAD_ABOVEDOT = 0x86;
0409: /** @since 1.2 */
0410: public static final int VK_DEAD_DIAERESIS = 0x87;
0411: /** @since 1.2 */
0412: public static final int VK_DEAD_ABOVERING = 0x88;
0413: /** @since 1.2 */
0414: public static final int VK_DEAD_DOUBLEACUTE = 0x89;
0415: /** @since 1.2 */
0416: public static final int VK_DEAD_CARON = 0x8a;
0417: /** @since 1.2 */
0418: public static final int VK_DEAD_CEDILLA = 0x8b;
0419: /** @since 1.2 */
0420: public static final int VK_DEAD_OGONEK = 0x8c;
0421: /** @since 1.2 */
0422: public static final int VK_DEAD_IOTA = 0x8d;
0423: /** @since 1.2 */
0424: public static final int VK_DEAD_VOICED_SOUND = 0x8e;
0425: /** @since 1.2 */
0426: public static final int VK_DEAD_SEMIVOICED_SOUND = 0x8f;
0427: /** @since 1.2 */
0428: public static final int VK_AMPERSAND = 0x96;
0429: /** @since 1.2 */
0430: public static final int VK_ASTERISK = 0x97;
0431: /** @since 1.2 */
0432: public static final int VK_QUOTEDBL = 0x98;
0433: /** @since 1.2 */
0434: public static final int VK_LESS = 0x99;
0435: /** @since 1.2 */
0436: public static final int VK_GREATER = 0xa0;
0437: /** @since 1.2 */
0438: public static final int VK_BRACELEFT = 0xa1;
0439: /** @since 1.2 */
0440: public static final int VK_BRACERIGHT = 0xa2;
0441: /**
0442: * Constant for the "@" key.
0443: * @since 1.2
0444: */
0445: public static final int VK_AT = 0x0200;
0446: /**
0447: * Constant for the ":" key.
0448: * @since 1.2
0449: */
0450: public static final int VK_COLON = 0x0201;
0451: /**
0452: * Constant for the "^" key.
0453: * @since 1.2
0454: */
0455: public static final int VK_CIRCUMFLEX = 0x0202;
0456: /**
0457: * Constant for the "$" key.
0458: * @since 1.2
0459: */
0460: public static final int VK_DOLLAR = 0x0203;
0461: /**
0462: * Constant for the Euro currency sign key.
0463: * @since 1.2
0464: */
0465: public static final int VK_EURO_SIGN = 0x0204;
0466: /**
0467: * Constant for the "!" key.
0468: * @since 1.2
0469: */
0470: public static final int VK_EXCLAMATION_MARK = 0x0205;
0471: /**
0472: * Constant for the inverted exclamation mark key.
0473: * @since 1.2
0474: */
0475: public static final int VK_INVERTED_EXCLAMATION_MARK = 0x0206;
0476: /**
0477: * Constant for the "(" key.
0478: * @since 1.2
0479: */
0480: public static final int VK_LEFT_PARENTHESIS = 0x0207;
0481: /**
0482: * Constant for the "#" key.
0483: * @since 1.2
0484: */
0485: public static final int VK_NUMBER_SIGN = 0x0208;
0486: /**
0487: * Constant for the "+" key.
0488: * @since 1.2
0489: */
0490: public static final int VK_PLUS = 0x0209;
0491: /**
0492: * Constant for the ")" key.
0493: * @since 1.2
0494: */
0495: public static final int VK_RIGHT_PARENTHESIS = 0x020A;
0496: /**
0497: * Constant for the "_" key.
0498: * @since 1.2
0499: */
0500: public static final int VK_UNDERSCORE = 0x020B;
0501: /* for input method support on Asian Keyboards */
0502:
0503: /* not clear what this means - listed in Win32 API */
0504: public static final int VK_FINAL = 0x0018;
0505: /** Constant for the Convert function key. */
0506:
0507: /* Japanese PC 106 keyboard, Japanese Solaris keyboard: henkan */
0508: public static final int VK_CONVERT = 0x001C;
0509: /** Constant for the Don't Convert function key. */
0510:
0511: /* Japanese PC 106 keyboard: muhenkan */
0512: public static final int VK_NONCONVERT = 0x001D;
0513: /** Constant for the Accept or Commit function key. */
0514:
0515: /* Japanese Solaris keyboard: kakutei */
0516: public static final int VK_ACCEPT = 0x001E;
0517: /* not clear what this means - listed in Win32 API */
0518: public static final int VK_MODECHANGE = 0x001F;
0519: /* replaced by VK_KANA_LOCK for Win32 and Solaris; might still be used on other platforms */
0520: public static final int VK_KANA = 0x0015;
0521: /* replaced by VK_INPUT_METHOD_ON_OFF for Win32 and Solaris; might still be used for other platforms */
0522: public static final int VK_KANJI = 0x0019;
0523: /**
0524: * Constant for the Alphanumeric function key.
0525: * @since 1.2
0526: */
0527:
0528: /* Japanese PC 106 keyboard: eisuu */
0529: public static final int VK_ALPHANUMERIC = 0x00F0;
0530: /**
0531: * Constant for the Katakana function key.
0532: * @since 1.2
0533: */
0534:
0535: /* Japanese PC 106 keyboard: katakana */
0536: public static final int VK_KATAKANA = 0x00F1;
0537: /**
0538: * Constant for the Hiragana function key.
0539: * @since 1.2
0540: */
0541:
0542: /* Japanese PC 106 keyboard: hiragana */
0543: public static final int VK_HIRAGANA = 0x00F2;
0544: /**
0545: * Constant for the Full-Width Characters function key.
0546: * @since 1.2
0547: */
0548:
0549: /* Japanese PC 106 keyboard: zenkaku */
0550: public static final int VK_FULL_WIDTH = 0x00F3;
0551: /**
0552: * Constant for the Half-Width Characters function key.
0553: * @since 1.2
0554: */
0555:
0556: /* Japanese PC 106 keyboard: hankaku */
0557: public static final int VK_HALF_WIDTH = 0x00F4;
0558: /**
0559: * Constant for the Roman Characters function key.
0560: * @since 1.2
0561: */
0562:
0563: /* Japanese PC 106 keyboard: roumaji */
0564: public static final int VK_ROMAN_CHARACTERS = 0x00F5;
0565: /**
0566: * Constant for the All Candidates function key.
0567: * @since 1.2
0568: */
0569:
0570: /* Japanese PC 106 keyboard - VK_CONVERT + ALT: zenkouho */
0571: public static final int VK_ALL_CANDIDATES = 0x0100;
0572: /**
0573: * Constant for the Previous Candidate function key.
0574: * @since 1.2
0575: */
0576:
0577: /* Japanese PC 106 keyboard - VK_CONVERT + SHIFT: maekouho */
0578: public static final int VK_PREVIOUS_CANDIDATE = 0x0101;
0579: /**
0580: * Constant for the Code Input function key.
0581: * @since 1.2
0582: */
0583:
0584: /* Japanese PC 106 keyboard - VK_ALPHANUMERIC + ALT: kanji bangou */
0585: public static final int VK_CODE_INPUT = 0x0102;
0586: /**
0587: * Constant for the Japanese-Katakana function key.
0588: * This key switches to a Japanese input method and selects its Katakana input mode.
0589: * @since 1.2
0590: */
0591:
0592: /* Japanese Macintosh keyboard - VK_JAPANESE_HIRAGANA + SHIFT */
0593: public static final int VK_JAPANESE_KATAKANA = 0x0103;
0594: /**
0595: * Constant for the Japanese-Hiragana function key.
0596: * This key switches to a Japanese input method and selects its Hiragana input mode.
0597: * @since 1.2
0598: */
0599:
0600: /* Japanese Macintosh keyboard */
0601: public static final int VK_JAPANESE_HIRAGANA = 0x0104;
0602: /**
0603: * Constant for the Japanese-Roman function key.
0604: * This key switches to a Japanese input method and selects its Roman-Direct input mode.
0605: * @since 1.2
0606: */
0607:
0608: /* Japanese Macintosh keyboard */
0609: public static final int VK_JAPANESE_ROMAN = 0x0105;
0610: /**
0611: * Constant for the locking Kana function key.
0612: * This key locks the keyboard into a Kana layout.
0613: * @since 1.3
0614: */
0615:
0616: /* Japanese PC 106 keyboard with special Windows driver - eisuu + Control; Japanese Solaris keyboard: kana */
0617: public static final int VK_KANA_LOCK = 0x0106;
0618: /**
0619: * Constant for the input method on/off key.
0620: * @since 1.3
0621: */
0622:
0623: /* Japanese PC 106 keyboard: kanji. Japanese Solaris keyboard: nihongo */
0624: public static final int VK_INPUT_METHOD_ON_OFF = 0x0107;
0625: /* for Sun keyboards */
0626:
0627: /** @since 1.2 */
0628: public static final int VK_CUT = 0xFFD1;
0629: /** @since 1.2 */
0630: public static final int VK_COPY = 0xFFCD;
0631: /** @since 1.2 */
0632: public static final int VK_PASTE = 0xFFCF;
0633: /** @since 1.2 */
0634: public static final int VK_UNDO = 0xFFCB;
0635: /** @since 1.2 */
0636: public static final int VK_AGAIN = 0xFFC9;
0637: /** @since 1.2 */
0638: public static final int VK_FIND = 0xFFD0;
0639: /** @since 1.2 */
0640: public static final int VK_PROPS = 0xFFCA;
0641: /** @since 1.2 */
0642: public static final int VK_STOP = 0xFFC8;
0643: /**
0644: * Constant for the Compose function key.
0645: * @since 1.2
0646: */
0647: public static final int VK_COMPOSE = 0xFF20;
0648: /**
0649: * Constant for the AltGraph function key.
0650: * @since 1.2
0651: */
0652: public static final int VK_ALT_GRAPH = 0xFF7E;
0653: /**
0654: * This value is used to indicate that the keyCode is unknown.
0655: * KEY_TYPED events do not have a keyCode value; this value
0656: * is used instead.
0657: */
0658: public static final int VK_UNDEFINED = 0x0;
0659: /**
0660: * KEY_PRESSED and KEY_RELEASED events which do not map to a
0661: * valid Unicode character use this for the keyChar value.
0662: */
0663: public static final char CHAR_UNDEFINED = 0xFFFF;
0664: /**
0665: * A constant indicating that the keyLocation is indeterminate
0666: * or not relevant.
0667: * KEY_TYPED events do not have a keyLocation; this value
0668: * is used instead.
0669: * @since 1.4
0670: */
0671: public static final int KEY_LOCATION_UNKNOWN = 0;
0672:
0673: /**
0674: * A constant indicating that the key pressed or released
0675: * is not distinguished as the left or right version of a key,
0676: * and did not originate on the numeric keypad (or did not
0677: * originate with a virtual key corresponding to the numeric
0678: * keypad).
0679: * @since 1.4
0680: */
0681: public static final int KEY_LOCATION_STANDARD = 1;
0682:
0683: /**
0684: * A constant indicating that the key pressed or released is in
0685: * the left key location (there is more than one possible location
0686: * for this key). Example: the left shift key.
0687: * @since 1.4
0688: */
0689: public static final int KEY_LOCATION_LEFT = 2;
0690:
0691: /**
0692: * A constant indicating that the key pressed or released is in
0693: * the right key location (there is more than one possible location
0694: * for this key). Example: the right shift key.
0695: * @since 1.4
0696: */
0697: public static final int KEY_LOCATION_RIGHT = 3;
0698:
0699: /**
0700: * A constant indicating that the key event originated on the
0701: * numeric keypad or with a virtual key corresponding to the
0702: * numeric keypad.
0703: * @since 1.4
0704: */
0705: public static final int KEY_LOCATION_NUMPAD = 4;
0706:
0707: /**
0708: * The unique value assigned to each of the keys on the
0709: * keyboard. There is a common set of key codes that
0710: * can be fired by most keyboards.
0711: * The symbolic name for a key code should be used rather
0712: * than the code value itself.
0713: *
0714: * @serial
0715: * @see getKeyCode()
0716: * @see setKeyCode()
0717: */
0718: int keyCode;
0719: /**
0720: * <code>keyChar</code> is a valid unicode character
0721: * that is fired by a key or a key combination on
0722: * a keyboard.
0723: *
0724: * @serial
0725: * @see getKeyChar()
0726: * @see setKeyChar()
0727: */
0728: char keyChar;
0729: /**
0730: * The location of the key on the keyboard.
0731: *
0732: * Some keys occur more than once on a keyboard, e.g. the left and
0733: * right shift keys. Additionally, some keys occur on the numeric
0734: * keypad. This variable is used to distinguish such keys.
0735: *
0736: * The only legal values are <code>KEY_LOCATION_UNKNOWN</code>,
0737: * <code>KEY_LOCATION_STANDARD</code>, <code>KEY_LOCATION_LEFT</code>,
0738: * <code>KEY_LOCATION_RIGHT</code>, and <code>KEY_LOCATION_NUMPAD</code>.
0739: *
0740: * @serial
0741: * @see getKeyLocation()
0742: */
0743: // int keyLocation;
0744: /*
0745: * JDK 1.1 serialVersionUID
0746: */
0747: private static final long serialVersionUID = -2352130953028126954L;
0748:
0749: /**
0750: * Constructs a <code>KeyEvent</code> object.
0751: * <p>Note that passing in an invalid <code>id</code> results in
0752: * unspecified behavior.
0753: *
0754: * @param source the <code>Component</code> that originated the event
0755: * @param id an integer identifying the type of event
0756: * @param when a long integer that specifies the time the event
0757: * occurred
0758: * @param modifiers the modifier keys down during event (shift, ctrl,
0759: * alt, meta)
0760: * Either extended _DOWN_MASK or old _MASK modifiers
0761: * should be used, but both models should not be mixed
0762: * in one event. Use of the extended modifiers is
0763: * preferred.
0764: * @param keyCode the integer code for an actual key, or VK_UNDEFINED
0765: * (for a key-typed event)
0766: * @param keyChar the Unicode character generated by this event, or
0767: * CHAR_UNDEFINED (for key-pressed and key-released
0768: * events which do not map to a valid Unicode character)
0769: * @param keyLocation identifies the key location. The only legal
0770: * values are <code>KEY_LOCATION_UNKNOWN</code>,
0771: * <code>KEY_LOCATION_STANDARD</code>, <code>KEY_LOCATION_LEFT</code>,
0772: * <code>KEY_LOCATION_RIGHT</code>, and <code>KEY_LOCATION_NUMPAD</code>.
0773: * @exception IllegalArgumentException
0774: * if <code>id</code> is <code>KEY_TYPED</code> and
0775: * <code>keyChar</code> is <code>CHAR_UNDEFINED</code>;
0776: * or if <code>id</code> is <code>KEY_TYPED</code> and
0777: * <code>keyCode</code> is not <code>VK_UNDEFINED</code>;
0778: * or if <code>id</code> is <code>KEY_TYPED</code> and
0779: * <code>keyLocation</code> is not <code>KEY_LOCATION_UNKNOWN</code>;
0780: * or if <code>keyLocation</code> is not one of the legal
0781: * values enumerated above.
0782: * @since 1.4
0783: */
0784:
0785: /* private KeyEvent(Component source, int id, long when, int modifiers,
0786: int keyCode, char keyChar, int keyLocation, boolean isProxyActive) {
0787: this(source, id, when, modifiers, keyCode, keyChar, keyLocation);
0788: this.isProxyActive = isProxyActive;
0789: }
0790: */
0791:
0792: public KeyEvent(Component source, int id, long when, int modifiers,
0793: int keyCode, char keyChar, int keyLocation) {
0794: super (source, id, when, modifiers);
0795: if (id == KEY_TYPED) {
0796: if (keyChar == CHAR_UNDEFINED) {
0797: throw new IllegalArgumentException("invalid keyChar");
0798: }
0799: if (keyCode != VK_UNDEFINED) {
0800: throw new IllegalArgumentException("invalid keyCode");
0801: }
0802: if (keyLocation != KEY_LOCATION_UNKNOWN) {
0803: throw new IllegalArgumentException(
0804: "invalid keyLocation");
0805: }
0806: }
0807:
0808: this .keyCode = keyCode;
0809: this .keyChar = keyChar;
0810:
0811: if ((keyLocation < KEY_LOCATION_UNKNOWN)
0812: || (keyLocation > KEY_LOCATION_NUMPAD)) {
0813: throw new IllegalArgumentException("invalid keyLocation");
0814: }
0815: //this.keyLocation = keyLocation;
0816: if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
0817: setNewModifiers();
0818: } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
0819: setOldModifiers();
0820: }
0821: }
0822:
0823: /**
0824: * Constructs a <code>KeyEvent</code> object.
0825: * <p>Note that passing in an invalid <code>id</code> results in
0826: * unspecified behavior.
0827: *
0828: * @param source the <code>Component</code> that originated the event
0829: * @param id an integer identifying the type of event
0830: * @param when a long integer that specifies the time the event
0831: * occurred
0832: * @param modifiers the modifier keys down during event (shift, ctrl,
0833: * alt, meta)
0834: * Either extended _DOWN_MASK or old _MASK modifiers
0835: * should be used, but both models should not be mixed
0836: * in one event. Use of the extended modifiers is
0837: * preferred.
0838: * @param keyCode the integer code for an actual key, or VK_UNDEFINED
0839: * (for a key-typed event)
0840: * @param keyChar the Unicode character generated by this event, or
0841: * CHAR_UNDEFINED (for key-pressed and key-released
0842: * events which do not map to a valid Unicode character)
0843: * @exception IllegalArgumentException if <code>id</code> is
0844: * <code>KEY_TYPED</code> and <code>keyChar</code> is
0845: * <code>CHAR_UNDEFINED</code>; or if <code>id</code> is
0846: * <code>KEY_TYPED</code> and <code>keyCode</code> is not
0847: * <code>VK_UNDEFINED</code>
0848: */
0849: public KeyEvent(Component source, int id, long when, int modifiers,
0850: int keyCode, char keyChar) {
0851: super (source, id, when, modifiers);
0852: if (id == KEY_TYPED) {
0853: if (keyChar == CHAR_UNDEFINED) {
0854: throw new IllegalArgumentException("invalid keyChar");
0855: }
0856: if (keyCode != VK_UNDEFINED) {
0857: throw new IllegalArgumentException("invalid keyCode");
0858: }
0859: /* if (keyLocation != KEY_LOCATION_UNKNOWN) {
0860: throw new IllegalArgumentException("invalid keyLocation");
0861: }
0862: */}
0863: this .keyCode = keyCode;
0864: this .keyChar = keyChar;
0865: }
0866:
0867: /**
0868: * @deprecated, as of JDK1.1
0869: */
0870: public KeyEvent(Component source, int id, long when, int modifiers,
0871: int keyCode) {
0872: this (source, id, when, modifiers, keyCode, (char) keyCode);
0873: }
0874:
0875: /**
0876: * Returns the integer keyCode associated with the key in this event.
0877: *
0878: * @return the integer code for an actual key on the keyboard.
0879: * (For <code>KEY_TYPED</code> events, the keyCode is
0880: * <code>VK_UNDEFINED</code>.)
0881: */
0882: public int getKeyCode() {
0883: return keyCode;
0884: }
0885:
0886: /**
0887: * Set the keyCode value to indicate a physical key.
0888: *
0889: * @param keyCode an integer corresponding to an actual key on the keyboard.
0890: */
0891: public void setKeyCode(int keyCode) {
0892: this .keyCode = keyCode;
0893: }
0894:
0895: /**
0896: * Returns the character associated with the key in this event.
0897: * For example, the key-typed event for shift + "a" returns the
0898: * value for "A".
0899: *
0900: * @return the Unicode character defined for this key event.
0901: * If no valid Unicode character exists for this key event,
0902: * keyChar is <code>CHAR_UNDEFINED</code>.
0903: */
0904: public char getKeyChar() {
0905: return keyChar;
0906: }
0907:
0908: /**
0909: * Set the keyChar value to indicate a logical character.
0910: *
0911: * @param keyChar a char corresponding to to the combination of keystrokes
0912: * that make up this event.
0913: */
0914: public void setKeyChar(char keyChar) {
0915: this .keyChar = keyChar;
0916: }
0917:
0918: /**
0919: * Set the modifiers to indicate additional keys that were held down
0920: * (e.g. shift, ctrl, alt, meta) defined as part of InputEvent.
0921: * <p>
0922: * NOTE: use of this method is not recommended, because many AWT
0923: * implementations do not recognize modifier changes. This is
0924: * especially true for <code>KEY_TYPED</code> events where the shift
0925: * modifier is changed.
0926: *
0927: * @param modifiers an integer combination of the modifier constants.
0928: * @see InputEvent
0929: * @deprecated, as of JDK1.1.4
0930: */
0931: public void setModifiers(int modifiers) {
0932: this .modifiers = modifiers;
0933: if ((getModifiers() != 0) && (getModifiersEx() == 0)) {
0934: setNewModifiers();
0935: } else if ((getModifiers() == 0) && (getModifiersEx() != 0)) {
0936: setOldModifiers();
0937: }
0938: }
0939:
0940: /**
0941: * Returns the location of the key that originated this key event.
0942: *
0943: * Some keys occur more than once on a keyboard, e.g. the left and
0944: * right shift keys. Additionally, some keys occur on the numeric
0945: * keypad. This provides a way of distinguishing such keys.
0946: *
0947: * @return the location of the key that was pressed or released.
0948: * Always returns <code>KEY_LOCATION_UNKNOWN</code> for
0949: * <code>KEY_TYPED</code> events.
0950: * @since 1.4
0951: */
0952:
0953: /* public int getKeyLocation() {
0954: return keyLocation;
0955: }
0956: */
0957:
0958: /**
0959: * Returns a String describing the keyCode, such as "HOME", "F1" or "A".
0960: * These strings can be localized by changing the awt.properties file.
0961: *
0962: * @return a string containing a text description for a physical key,
0963: * identified by its keyCode
0964: */
0965: public static String getKeyText(int keyCode) {
0966: if (keyCode >= VK_0 && keyCode <= VK_9 || keyCode >= VK_A
0967: && keyCode <= VK_Z) {
0968: return String.valueOf((char) keyCode);
0969: }
0970: // Check for other ASCII keyCodes.
0971: int index = ",./;=[\\]".indexOf(keyCode);
0972: if (index >= 0) {
0973: return String.valueOf((char) keyCode);
0974: }
0975: switch (keyCode) {
0976: case VK_ENTER:
0977: return Toolkit.getProperty("AWT.enter", "Enter");
0978:
0979: case VK_BACK_SPACE:
0980: return Toolkit.getProperty("AWT.backSpace", "Backspace");
0981:
0982: case VK_TAB:
0983: return Toolkit.getProperty("AWT.tab", "Tab");
0984:
0985: case VK_CANCEL:
0986: return Toolkit.getProperty("AWT.cancel", "Cancel");
0987:
0988: case VK_CLEAR:
0989: return Toolkit.getProperty("AWT.clear", "Clear");
0990:
0991: case VK_SHIFT:
0992: return Toolkit.getProperty("AWT.shift", "Shift");
0993:
0994: case VK_CONTROL:
0995: return Toolkit.getProperty("AWT.control", "Control");
0996:
0997: case VK_ALT:
0998: return Toolkit.getProperty("AWT.alt", "Alt");
0999:
1000: case VK_PAUSE:
1001: return Toolkit.getProperty("AWT.pause", "Pause");
1002:
1003: case VK_CAPS_LOCK:
1004: return Toolkit.getProperty("AWT.capsLock", "Caps Lock");
1005:
1006: case VK_ESCAPE:
1007: return Toolkit.getProperty("AWT.escape", "Escape");
1008:
1009: case VK_SPACE:
1010: return Toolkit.getProperty("AWT.space", "Space");
1011:
1012: case VK_PAGE_UP:
1013: return Toolkit.getProperty("AWT.pgup", "Page Up");
1014:
1015: case VK_PAGE_DOWN:
1016: return Toolkit.getProperty("AWT.pgdn", "Page Down");
1017:
1018: case VK_END:
1019: return Toolkit.getProperty("AWT.end", "End");
1020:
1021: case VK_HOME:
1022: return Toolkit.getProperty("AWT.home", "Home");
1023:
1024: case VK_LEFT:
1025: return Toolkit.getProperty("AWT.left", "Left");
1026:
1027: case VK_UP:
1028: return Toolkit.getProperty("AWT.up", "Up");
1029:
1030: case VK_RIGHT:
1031: return Toolkit.getProperty("AWT.right", "Right");
1032:
1033: case VK_DOWN:
1034: return Toolkit.getProperty("AWT.down", "Down");
1035:
1036: // handled by ASCII value above:
1037: // comma, period, slash, 0-9, semicolon, equals, A-Z,
1038: // open_bracket, back_slash, close_bracket
1039:
1040: // numpad numeric keys handled below
1041: case VK_MULTIPLY:
1042: return Toolkit.getProperty("AWT.multiply", "NumPad *");
1043:
1044: case VK_ADD:
1045: return Toolkit.getProperty("AWT.add", "NumPad +");
1046:
1047: case VK_SEPARATOR:
1048: return Toolkit.getProperty("AWT.separator", "NumPad ,");
1049:
1050: case VK_SUBTRACT:
1051: return Toolkit.getProperty("AWT.subtract", "NumPad -");
1052:
1053: case VK_DECIMAL:
1054: return Toolkit.getProperty("AWT.decimal", "NumPad .");
1055:
1056: case VK_DIVIDE:
1057: return Toolkit.getProperty("AWT.divide", "NumPad /");
1058:
1059: case VK_DELETE:
1060: return Toolkit.getProperty("AWT.delete", "Delete");
1061:
1062: case VK_NUM_LOCK:
1063: return Toolkit.getProperty("AWT.numLock", "Num Lock");
1064:
1065: case VK_SCROLL_LOCK:
1066: return Toolkit.getProperty("AWT.scrollLock", "Scroll Lock");
1067:
1068: case VK_F1:
1069: return Toolkit.getProperty("AWT.f1", "F1");
1070:
1071: case VK_F2:
1072: return Toolkit.getProperty("AWT.f2", "F2");
1073:
1074: case VK_F3:
1075: return Toolkit.getProperty("AWT.f3", "F3");
1076:
1077: case VK_F4:
1078: return Toolkit.getProperty("AWT.f4", "F4");
1079:
1080: case VK_F5:
1081: return Toolkit.getProperty("AWT.f5", "F5");
1082:
1083: case VK_F6:
1084: return Toolkit.getProperty("AWT.f6", "F6");
1085:
1086: case VK_F7:
1087: return Toolkit.getProperty("AWT.f7", "F7");
1088:
1089: case VK_F8:
1090: return Toolkit.getProperty("AWT.f8", "F8");
1091:
1092: case VK_F9:
1093: return Toolkit.getProperty("AWT.f9", "F9");
1094:
1095: case VK_F10:
1096: return Toolkit.getProperty("AWT.f10", "F10");
1097:
1098: case VK_F11:
1099: return Toolkit.getProperty("AWT.f11", "F11");
1100:
1101: case VK_F12:
1102: return Toolkit.getProperty("AWT.f12", "F12");
1103:
1104: case VK_F13:
1105: return Toolkit.getProperty("AWT.f13", "F13");
1106:
1107: case VK_F14:
1108: return Toolkit.getProperty("AWT.f14", "F14");
1109:
1110: case VK_F15:
1111: return Toolkit.getProperty("AWT.f15", "F15");
1112:
1113: case VK_F16:
1114: return Toolkit.getProperty("AWT.f16", "F16");
1115:
1116: case VK_F17:
1117: return Toolkit.getProperty("AWT.f17", "F17");
1118:
1119: case VK_F18:
1120: return Toolkit.getProperty("AWT.f18", "F18");
1121:
1122: case VK_F19:
1123: return Toolkit.getProperty("AWT.f19", "F19");
1124:
1125: case VK_F20:
1126: return Toolkit.getProperty("AWT.f20", "F20");
1127:
1128: case VK_F21:
1129: return Toolkit.getProperty("AWT.f21", "F21");
1130:
1131: case VK_F22:
1132: return Toolkit.getProperty("AWT.f22", "F22");
1133:
1134: case VK_F23:
1135: return Toolkit.getProperty("AWT.f23", "F23");
1136:
1137: case VK_F24:
1138: return Toolkit.getProperty("AWT.f24", "F24");
1139:
1140: case VK_PRINTSCREEN:
1141: return Toolkit.getProperty("AWT.printScreen",
1142: "Print Screen");
1143:
1144: case VK_INSERT:
1145: return Toolkit.getProperty("AWT.insert", "Insert");
1146:
1147: case VK_HELP:
1148: return Toolkit.getProperty("AWT.help", "Help");
1149:
1150: case VK_META:
1151: return Toolkit.getProperty("AWT.meta", "Meta");
1152:
1153: case VK_BACK_QUOTE:
1154: return Toolkit.getProperty("AWT.backQuote", "Back Quote");
1155:
1156: case VK_QUOTE:
1157: return Toolkit.getProperty("AWT.quote", "Quote");
1158:
1159: case VK_KP_UP:
1160: return Toolkit.getProperty("AWT.up", "Up");
1161:
1162: case VK_KP_DOWN:
1163: return Toolkit.getProperty("AWT.down", "Down");
1164:
1165: case VK_KP_LEFT:
1166: return Toolkit.getProperty("AWT.left", "Left");
1167:
1168: case VK_KP_RIGHT:
1169: return Toolkit.getProperty("AWT.right", "Right");
1170:
1171: case VK_DEAD_GRAVE:
1172: return Toolkit.getProperty("AWT.deadGrave", "Dead Grave");
1173:
1174: case VK_DEAD_ACUTE:
1175: return Toolkit.getProperty("AWT.deadAcute", "Dead Acute");
1176:
1177: case VK_DEAD_CIRCUMFLEX:
1178: return Toolkit.getProperty("AWT.deadCircumflex",
1179: "Dead Circumflex");
1180:
1181: case VK_DEAD_TILDE:
1182: return Toolkit.getProperty("AWT.deadTilde", "Dead Tilde");
1183:
1184: case VK_DEAD_MACRON:
1185: return Toolkit.getProperty("AWT.deadMacron", "Dead Macron");
1186:
1187: case VK_DEAD_BREVE:
1188: return Toolkit.getProperty("AWT.deadBreve", "Dead Breve");
1189:
1190: case VK_DEAD_ABOVEDOT:
1191: return Toolkit.getProperty("AWT.deadAboveDot",
1192: "Dead Above Dot");
1193:
1194: case VK_DEAD_DIAERESIS:
1195: return Toolkit.getProperty("AWT.deadDiaeresis",
1196: "Dead Diaeresis");
1197:
1198: case VK_DEAD_ABOVERING:
1199: return Toolkit.getProperty("AWT.deadAboveRing",
1200: "Dead Above Ring");
1201:
1202: case VK_DEAD_DOUBLEACUTE:
1203: return Toolkit.getProperty("AWT.deadDoubleAcute",
1204: "Dead Double Acute");
1205:
1206: case VK_DEAD_CARON:
1207: return Toolkit.getProperty("AWT.deadCaron", "Dead Caron");
1208:
1209: case VK_DEAD_CEDILLA:
1210: return Toolkit.getProperty("AWT.deadCedilla",
1211: "Dead Cedilla");
1212:
1213: case VK_DEAD_OGONEK:
1214: return Toolkit.getProperty("AWT.deadOgonek", "Dead Ogonek");
1215:
1216: case VK_DEAD_IOTA:
1217: return Toolkit.getProperty("AWT.deadIota", "Dead Iota");
1218:
1219: case VK_DEAD_VOICED_SOUND:
1220: return Toolkit.getProperty("AWT.deadVoicedSound",
1221: "Dead Voiced Sound");
1222:
1223: case VK_DEAD_SEMIVOICED_SOUND:
1224: return Toolkit.getProperty("AWT.deadSemivoicedSound",
1225: "Dead Semivoiced Sound");
1226:
1227: case VK_AMPERSAND:
1228: return Toolkit.getProperty("AWT.ampersand", "Ampersand");
1229:
1230: case VK_ASTERISK:
1231: return Toolkit.getProperty("AWT.asterisk", "Asterisk");
1232:
1233: case VK_QUOTEDBL:
1234: return Toolkit.getProperty("AWT.quoteDbl", "Double Quote");
1235:
1236: case VK_LESS:
1237: return Toolkit.getProperty("AWT.Less", "Less");
1238:
1239: case VK_GREATER:
1240: return Toolkit.getProperty("AWT.greater", "Greater");
1241:
1242: case VK_BRACELEFT:
1243: return Toolkit.getProperty("AWT.braceLeft", "Left Brace");
1244:
1245: case VK_BRACERIGHT:
1246: return Toolkit.getProperty("AWT.braceRight", "Right Brace");
1247:
1248: case VK_AT:
1249: return Toolkit.getProperty("AWT.at", "At");
1250:
1251: case VK_COLON:
1252: return Toolkit.getProperty("AWT.colon", "Colon");
1253:
1254: case VK_CIRCUMFLEX:
1255: return Toolkit.getProperty("AWT.circumflex", "Circumflex");
1256:
1257: case VK_DOLLAR:
1258: return Toolkit.getProperty("AWT.dollar", "Dollar");
1259:
1260: case VK_EURO_SIGN:
1261: return Toolkit.getProperty("AWT.euro", "Euro");
1262:
1263: case VK_EXCLAMATION_MARK:
1264: return Toolkit.getProperty("AWT.exclamationMark",
1265: "Exclamation Mark");
1266:
1267: case VK_INVERTED_EXCLAMATION_MARK:
1268: return Toolkit.getProperty("AWT.invertedExclamationMark",
1269: "Inverted Exclamation Mark");
1270:
1271: case VK_LEFT_PARENTHESIS:
1272: return Toolkit.getProperty("AWT.leftParenthesis",
1273: "Left Parenthesis");
1274:
1275: case VK_NUMBER_SIGN:
1276: return Toolkit.getProperty("AWT.numberSign", "Number Sign");
1277:
1278: case VK_MINUS:
1279: return Toolkit.getProperty("AWT.minus", "Minus");
1280:
1281: case VK_PLUS:
1282: return Toolkit.getProperty("AWT.plus", "Plus");
1283:
1284: case VK_RIGHT_PARENTHESIS:
1285: return Toolkit.getProperty("AWT.rightParenthesis",
1286: "Right Parenthesis");
1287:
1288: case VK_UNDERSCORE:
1289: return Toolkit.getProperty("AWT.underscore", "Underscore");
1290:
1291: case VK_FINAL:
1292: return Toolkit.getProperty("AWT.final", "Final");
1293:
1294: case VK_CONVERT:
1295: return Toolkit.getProperty("AWT.convert", "Convert");
1296:
1297: case VK_NONCONVERT:
1298: return Toolkit.getProperty("AWT.noconvert", "No Convert");
1299:
1300: case VK_ACCEPT:
1301: return Toolkit.getProperty("AWT.accept", "Accept");
1302:
1303: case VK_MODECHANGE:
1304: return Toolkit.getProperty("AWT.modechange", "Mode Change");
1305:
1306: case VK_KANA:
1307: return Toolkit.getProperty("AWT.kana", "Kana");
1308:
1309: case VK_KANJI:
1310: return Toolkit.getProperty("AWT.kanji", "Kanji");
1311:
1312: case VK_ALPHANUMERIC:
1313: return Toolkit.getProperty("AWT.alphanumeric",
1314: "Alphanumeric");
1315:
1316: case VK_KATAKANA:
1317: return Toolkit.getProperty("AWT.katakana", "Katakana");
1318:
1319: case VK_HIRAGANA:
1320: return Toolkit.getProperty("AWT.hiragana", "Hiragana");
1321:
1322: case VK_FULL_WIDTH:
1323: return Toolkit.getProperty("AWT.fullWidth", "Full-Width");
1324:
1325: case VK_HALF_WIDTH:
1326: return Toolkit.getProperty("AWT.halfWidth", "Half-Width");
1327:
1328: case VK_ROMAN_CHARACTERS:
1329: return Toolkit.getProperty("AWT.romanCharacters",
1330: "Roman Characters");
1331:
1332: case VK_ALL_CANDIDATES:
1333: return Toolkit.getProperty("AWT.allCandidates",
1334: "All Candidates");
1335:
1336: case VK_PREVIOUS_CANDIDATE:
1337: return Toolkit.getProperty("AWT.previousCandidate",
1338: "Previous Candidate");
1339:
1340: case VK_CODE_INPUT:
1341: return Toolkit.getProperty("AWT.codeInput", "Code Input");
1342:
1343: case VK_JAPANESE_KATAKANA:
1344: return Toolkit.getProperty("AWT.japaneseKatakana",
1345: "Japanese Katakana");
1346:
1347: case VK_JAPANESE_HIRAGANA:
1348: return Toolkit.getProperty("AWT.japaneseHiragana",
1349: "Japanese Hiragana");
1350:
1351: case VK_JAPANESE_ROMAN:
1352: return Toolkit.getProperty("AWT.japaneseRoman",
1353: "Japanese Roman");
1354:
1355: case VK_KANA_LOCK:
1356: return Toolkit.getProperty("AWT.kanaLock", "Kana Lock");
1357:
1358: case VK_INPUT_METHOD_ON_OFF:
1359: return Toolkit.getProperty("AWT.inputMethodOnOff",
1360: "Input Method On/Off");
1361:
1362: case VK_AGAIN:
1363: return Toolkit.getProperty("AWT.again", "Again");
1364:
1365: case VK_UNDO:
1366: return Toolkit.getProperty("AWT.undo", "Undo");
1367:
1368: case VK_COPY:
1369: return Toolkit.getProperty("AWT.copy", "Copy");
1370:
1371: case VK_PASTE:
1372: return Toolkit.getProperty("AWT.paste", "Paste");
1373:
1374: case VK_CUT:
1375: return Toolkit.getProperty("AWT.cut", "Cut");
1376:
1377: case VK_FIND:
1378: return Toolkit.getProperty("AWT.find", "Find");
1379:
1380: case VK_PROPS:
1381: return Toolkit.getProperty("AWT.props", "Props");
1382:
1383: case VK_STOP:
1384: return Toolkit.getProperty("AWT.stop", "Stop");
1385:
1386: case VK_COMPOSE:
1387: return Toolkit.getProperty("AWT.compose", "Compose");
1388:
1389: case VK_ALT_GRAPH:
1390: return Toolkit.getProperty("AWT.altGraph", "Alt Graph");
1391: }
1392: if (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9) {
1393: String numpad = Toolkit.getProperty("AWT.numpad", "NumPad");
1394: char c = (char) (keyCode - VK_NUMPAD0 + '0');
1395: return numpad + "-" + c;
1396: }
1397: String unknown = Toolkit.getProperty("AWT.unknown",
1398: "Unknown keyCode");
1399: return unknown + ": 0x" + Integer.toString(keyCode, 16);
1400: }
1401:
1402: /**
1403: * Returns a String describing the modifier key(s), such as "Shift",
1404: * or "Ctrl+Shift". These strings can be localized by changing the
1405: * awt.properties file.
1406: *
1407: * @return string a text description of the combination of modifier
1408: * keys that were held down during the event
1409: */
1410: public static String getKeyModifiersText(int modifiers) {
1411: StringBuffer buf = new StringBuffer();
1412: if ((modifiers & InputEvent.META_MASK) != 0) {
1413: buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
1414: buf.append("+");
1415: }
1416: if ((modifiers & InputEvent.CTRL_MASK) != 0) {
1417: buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
1418: buf.append("+");
1419: }
1420: if ((modifiers & InputEvent.ALT_MASK) != 0) {
1421: buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
1422: buf.append("+");
1423: }
1424: if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
1425: buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
1426: buf.append("+");
1427: }
1428: if ((modifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
1429: buf
1430: .append(Toolkit.getProperty("AWT.altGraph",
1431: "Alt Graph"));
1432: buf.append("+");
1433: }
1434: if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
1435: buf.append(Toolkit.getProperty("AWT.button1", "Button1"));
1436: buf.append("+");
1437: }
1438: if (buf.length() > 0) {
1439: buf.setLength(buf.length() - 1); // remove trailing '+'
1440: }
1441: return buf.toString();
1442: }
1443:
1444: /**
1445: * Returns whether the key in this event is an "action" key.
1446: * Typically an action key does not fire a unicode character and is
1447: * not a modifier key.
1448: *
1449: * @return <code>true</code> if the key is an "action" key,
1450: * <code>false</code> otherwise
1451: */
1452: public boolean isActionKey() {
1453: switch (keyCode) {
1454: case VK_HOME:
1455: case VK_END:
1456: case VK_PAGE_UP:
1457: case VK_PAGE_DOWN:
1458: case VK_UP:
1459: case VK_DOWN:
1460: case VK_LEFT:
1461: case VK_RIGHT:
1462: case VK_KP_LEFT:
1463: case VK_KP_UP:
1464: case VK_KP_RIGHT:
1465: case VK_KP_DOWN:
1466: case VK_F1:
1467: case VK_F2:
1468: case VK_F3:
1469: case VK_F4:
1470: case VK_F5:
1471: case VK_F6:
1472: case VK_F7:
1473: case VK_F8:
1474: case VK_F9:
1475: case VK_F10:
1476: case VK_F11:
1477: case VK_F12:
1478: case VK_F13:
1479: case VK_F14:
1480: case VK_F15:
1481: case VK_F16:
1482: case VK_F17:
1483: case VK_F18:
1484: case VK_F19:
1485: case VK_F20:
1486: case VK_F21:
1487: case VK_F22:
1488: case VK_F23:
1489: case VK_F24:
1490: case VK_PRINTSCREEN:
1491: case VK_SCROLL_LOCK:
1492: case VK_CAPS_LOCK:
1493: case VK_NUM_LOCK:
1494: case VK_PAUSE:
1495: case VK_INSERT:
1496: case VK_FINAL:
1497: case VK_CONVERT:
1498: case VK_NONCONVERT:
1499: case VK_ACCEPT:
1500: case VK_MODECHANGE:
1501: case VK_KANA:
1502: case VK_KANJI:
1503: case VK_ALPHANUMERIC:
1504: case VK_KATAKANA:
1505: case VK_HIRAGANA:
1506: case VK_FULL_WIDTH:
1507: case VK_HALF_WIDTH:
1508: case VK_ROMAN_CHARACTERS:
1509: case VK_ALL_CANDIDATES:
1510: case VK_PREVIOUS_CANDIDATE:
1511: case VK_CODE_INPUT:
1512: case VK_JAPANESE_KATAKANA:
1513: case VK_JAPANESE_HIRAGANA:
1514: case VK_JAPANESE_ROMAN:
1515: case VK_KANA_LOCK:
1516: case VK_INPUT_METHOD_ON_OFF:
1517: case VK_AGAIN:
1518: case VK_UNDO:
1519: case VK_COPY:
1520: case VK_PASTE:
1521: case VK_CUT:
1522: case VK_FIND:
1523: case VK_PROPS:
1524: case VK_STOP:
1525: case VK_HELP:
1526: return true;
1527: }
1528: return false;
1529: }
1530:
1531: /**
1532: * Returns a parameter string identifying this event.
1533: * This method is useful for event logging and for debugging.
1534: *
1535: * @return a string identifying the event and its attributes
1536: */
1537: public String paramString() {
1538: String typeStr;
1539: switch (id) {
1540: case KEY_PRESSED:
1541: typeStr = "KEY_PRESSED";
1542: break;
1543:
1544: case KEY_RELEASED:
1545: typeStr = "KEY_RELEASED";
1546: break;
1547:
1548: case KEY_TYPED:
1549: typeStr = "KEY_TYPED";
1550: break;
1551:
1552: default:
1553: typeStr = "unknown type";
1554: }
1555: String str = typeStr + ",keyCode=" + keyCode;
1556: if (isActionKey() || keyCode == VK_ENTER
1557: || keyCode == VK_BACK_SPACE || keyCode == VK_TAB
1558: || keyCode == VK_ESCAPE || keyCode == VK_DELETE
1559: || (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9)
1560: || keyCode == VK_COMPOSE || keyCode == VK_ALT_GRAPH) {
1561: str += "," + getKeyText(keyCode);
1562: } else if (keyChar == '\n' || keyChar == '\b'
1563: || keyChar == '\t' || keyChar == VK_ESCAPE
1564: || keyChar == VK_DELETE) {
1565: str += "," + getKeyText(keyChar);
1566: } else {
1567: str += ",keyChar='" + keyChar + "'";
1568: }
1569: if (getModifiers() != 0) {
1570: str += ",modifiers=" + getKeyModifiersText(modifiers);
1571: }
1572: if (getModifiersEx() != 0) {
1573: str += ",extModifiers=" + getModifiersExText(modifiers);
1574: }
1575:
1576: /*
1577: String locationStr;
1578: switch (keyLocation) {
1579: case KEY_LOCATION_UNKNOWN:
1580: locationStr = "KEY_LOCATION_UNKNOWN";
1581: break;
1582: case KEY_LOCATION_STANDARD:
1583: locationStr = "KEY_LOCATION_STANDARD";
1584: break;
1585: case KEY_LOCATION_LEFT:
1586: locationStr = "KEY_LOCATION_LEFT";
1587: break;
1588: case KEY_LOCATION_RIGHT:
1589: locationStr = "KEY_LOCATION_RIGHT";
1590: break;
1591: case KEY_LOCATION_NUMPAD:
1592: locationStr = "KEY_LOCATION_NUMPAD";
1593: break;
1594: default:
1595: locationStr = "KEY_LOCATION_UNKNOWN";
1596: break;
1597: }
1598: str += ",keyLocation=" + locationStr;
1599: */
1600: return str;
1601: }
1602:
1603: /**
1604: * Sets new modifiers by the old ones. The key modifiers
1605: * override overlaping mouse modifiers.
1606: */
1607:
1608: private void setNewModifiers() {
1609: if ((modifiers & SHIFT_MASK) != 0) {
1610: modifiers |= SHIFT_DOWN_MASK;
1611: }
1612: if ((modifiers & ALT_MASK) != 0) {
1613: modifiers |= ALT_DOWN_MASK;
1614: }
1615: if ((modifiers & CTRL_MASK) != 0) {
1616: modifiers |= CTRL_DOWN_MASK;
1617: }
1618: if ((modifiers & META_MASK) != 0) {
1619: modifiers |= META_DOWN_MASK;
1620: }
1621: if ((modifiers & ALT_GRAPH_MASK) != 0) {
1622: modifiers |= ALT_GRAPH_DOWN_MASK;
1623: }
1624: if ((modifiers & BUTTON1_MASK) != 0) {
1625: modifiers |= BUTTON1_DOWN_MASK;
1626: }
1627: }
1628:
1629: /**
1630: * Sets old modifiers by the new ones.
1631: */
1632:
1633: private void setOldModifiers() {
1634: if ((modifiers & SHIFT_DOWN_MASK) != 0) {
1635: modifiers |= SHIFT_MASK;
1636: }
1637: if ((modifiers & ALT_DOWN_MASK) != 0) {
1638: modifiers |= ALT_MASK;
1639: }
1640: if ((modifiers & CTRL_DOWN_MASK) != 0) {
1641: modifiers |= CTRL_MASK;
1642: }
1643: if ((modifiers & META_DOWN_MASK) != 0) {
1644: modifiers |= META_MASK;
1645: }
1646: if ((modifiers & ALT_GRAPH_DOWN_MASK) != 0) {
1647: modifiers |= ALT_GRAPH_MASK;
1648: }
1649: if ((modifiers & BUTTON1_DOWN_MASK) != 0) {
1650: modifiers |= BUTTON1_MASK;
1651: }
1652: }
1653:
1654: /**
1655: * Sets new modifiers by the old ones. The key modifiers
1656: * override overlaping mouse modifiers.
1657: * @serial
1658: */
1659: private void readObject(ObjectInputStream s) throws IOException,
1660: ClassNotFoundException {
1661: s.defaultReadObject();
1662: if (getModifiers() != 0 && getModifiersEx() == 0) {
1663: setNewModifiers();
1664: }
1665: }
1666:
1667: /**
1668: * Set the source of this KeyEvent. Dispatching this event subsequent
1669: * to this operation will send this event to the new Object.
1670: *
1671: * @param newSource the KeyEvent's new source.
1672: */
1673: public void setSource(Object newSource) {
1674: source = newSource;
1675: }
1676: }
|