home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / event / KeyEvent.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  26.9 KB  |  622 lines

  1. /*
  2.  * @(#)KeyEvent.java    1.28 98/03/18
  3.  *
  4.  * Copyright 1996-1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.event;
  16.  
  17. import java.awt.Event;
  18. import java.awt.Component;
  19. import java.awt.Toolkit;
  20.  
  21. /**
  22.  * An event which indicates that a keystroke occurred in a component.
  23.  * <P>
  24.  * This low-level event is generated by a component object (such as a text 
  25.  * field) when a key is pressed, released, or typed (pressed and released). 
  26.  * The event is passed to every <code>KeyListener</code>
  27.  * or <code>KeyAdapter</code> object which registered to receive such
  28.  * events using the component's <code>addKeyListener</code> method.
  29.  * (<code>KeyAdapter</code> objects implement the 
  30.  * <code>KeyListener</code> interface.) Each such listener object 
  31.  * gets this <code>KeyEvent</code> when the event occurs.
  32.  *
  33.  * @see KeyAdapter
  34.  * @see KeyListener
  35.  * @see <a href="http://java.sun.com/docs/books/tutorial/post1.0/ui/keylistener.html">Tutorial: Writing a Key Listener</a>
  36.  * @see <a href="http://www.awl.com/cp/javaseries/jcl1_2.html">Reference: The Java Class Libraries (update file)</a>
  37.  *
  38.  * @version 1.28 03/18/98
  39.  * @author Carl Quinn
  40.  * @author Amy Fowler
  41.  */
  42. public class KeyEvent extends InputEvent {
  43.  
  44.     /**
  45.      * The first number in the range of ids used for key events.
  46.      */
  47.     public static final int KEY_FIRST = 400;
  48.  
  49.     /**
  50.      * The last number in the range of ids used for key events.
  51.      */
  52.     public static final int KEY_LAST  = 402;
  53.  
  54.     /**
  55.      * The "key typed" event.  This event is generated by a combination
  56.      * of a key press followed by a key release.
  57.      */
  58.     public static final int KEY_TYPED = KEY_FIRST;
  59.  
  60.     /**
  61.      * The "key pressed" event. This event is generated when a key
  62.      * is pushed down.
  63.      */
  64.     public static final int KEY_PRESSED = 1 + KEY_FIRST; //Event.KEY_PRESS
  65.  
  66.     /**
  67.      * The "key released" event. This event is generated when a key
  68.      * is let up.
  69.      */
  70.     public static final int KEY_RELEASED = 2 + KEY_FIRST; //Event.KEY_RELEASE
  71.  
  72.     /**
  73.      * Virtual key codes.  These codes report which keyboard key has
  74.      * been pressed, rather than a character generated by the combination
  75.      * of one or more keystrokes (like "A", which comes from shift and "a").  
  76.      * <P>
  77.      * For example, pressing the Shift key will cause a KEY_PRESSED event 
  78.      * with a VK_SHIFT keyCode, while pressing the 'a' key will result in 
  79.      * a VK_A keyCode.  After the 'a' key is released, a KEY_RELEASED event 
  80.      * will be fired with VK_A, followed by a KEY_TYPED event with a keyChar 
  81.      * value of 'A'.  
  82.      * <P>
  83.      * Note: Key combinations which do not result in characters,
  84.      * such as action keys like F1, do not generate KEY_TYPED events.
  85.      * <P>
  86.      * Note: not all keyboards or systems are capable of generating all
  87.      * virtual key codes.  No attempt is made in Java to artificially
  88.      * generate these keys.
  89.      * <P>
  90.      * WARNING:  aside from those keys where are defined by the Java language
  91.      * (VK_ENTER, VK_BACK_SPACE, and VK_TAB), do not rely on the values of these
  92.      * constants.  Sun reserves the right to change these values as needed
  93.      * to accomodate a wider range of keyboards in the future.  
  94.      */
  95.     public static final int VK_ENTER          = '\n';
  96.     public static final int VK_BACK_SPACE     = '\b';
  97.     public static final int VK_TAB            = '\t';
  98.     public static final int VK_CANCEL         = 0x03;
  99.     public static final int VK_CLEAR          = 0x0C;
  100.     public static final int VK_SHIFT          = 0x10;
  101.     public static final int VK_CONTROL        = 0x11;
  102.     public static final int VK_ALT            = 0x12;
  103.     public static final int VK_PAUSE          = 0x13;
  104.     public static final int VK_CAPS_LOCK      = 0x14;
  105.     public static final int VK_ESCAPE         = 0x1B;
  106.     public static final int VK_SPACE          = 0x20;
  107.     public static final int VK_PAGE_UP        = 0x21;
  108.     public static final int VK_PAGE_DOWN      = 0x22;
  109.     public static final int VK_END            = 0x23;
  110.     public static final int VK_HOME           = 0x24;
  111.     public static final int VK_LEFT           = 0x25;
  112.     public static final int VK_UP             = 0x26;
  113.     public static final int VK_RIGHT          = 0x27;
  114.     public static final int VK_DOWN           = 0x28;
  115.     public static final int VK_COMMA          = 0x2C;
  116.     public static final int VK_PERIOD         = 0x2E;
  117.     public static final int VK_SLASH          = 0x2F;
  118.  
  119.     /** VK_0 thru VK_9 are the same as ASCII '0' thru '9' (0x30 - 0x39) */
  120.     public static final int VK_0              = 0x30;
  121.     public static final int VK_1              = 0x31;
  122.     public static final int VK_2              = 0x32;
  123.     public static final int VK_3              = 0x33;
  124.     public static final int VK_4              = 0x34;
  125.     public static final int VK_5              = 0x35;
  126.     public static final int VK_6              = 0x36;
  127.     public static final int VK_7              = 0x37;
  128.     public static final int VK_8              = 0x38;
  129.     public static final int VK_9              = 0x39;
  130.  
  131.     public static final int VK_SEMICOLON      = 0x3B;
  132.     public static final int VK_EQUALS         = 0x3D;
  133.  
  134.     /** VK_A thru VK_Z are the same as ASCII 'A' thru 'Z' (0x41 - 0x5A) */
  135.     public static final int VK_A              = 0x41;
  136.     public static final int VK_B              = 0x42;
  137.     public static final int VK_C              = 0x43;
  138.     public static final int VK_D              = 0x44;
  139.     public static final int VK_E              = 0x45;
  140.     public static final int VK_F              = 0x46;
  141.     public static final int VK_G              = 0x47;
  142.     public static final int VK_H              = 0x48;
  143.     public static final int VK_I              = 0x49;
  144.     public static final int VK_J              = 0x4A;
  145.     public static final int VK_K              = 0x4B;
  146.     public static final int VK_L              = 0x4C;
  147.     public static final int VK_M              = 0x4D;
  148.     public static final int VK_N              = 0x4E;
  149.     public static final int VK_O              = 0x4F;
  150.     public static final int VK_P              = 0x50;
  151.     public static final int VK_Q              = 0x51;
  152.     public static final int VK_R              = 0x52;
  153.     public static final int VK_S              = 0x53;
  154.     public static final int VK_T              = 0x54;
  155.     public static final int VK_U              = 0x55;
  156.     public static final int VK_V              = 0x56;
  157.     public static final int VK_W              = 0x57;
  158.     public static final int VK_X              = 0x58;
  159.     public static final int VK_Y              = 0x59;
  160.     public static final int VK_Z              = 0x5A;
  161.  
  162.     public static final int VK_OPEN_BRACKET   = 0x5B;
  163.     public static final int VK_BACK_SLASH     = 0x5C;
  164.     public static final int VK_CLOSE_BRACKET  = 0x5D;
  165.  
  166.     public static final int VK_NUMPAD0        = 0x60;
  167.     public static final int VK_NUMPAD1        = 0x61;
  168.     public static final int VK_NUMPAD2        = 0x62;
  169.     public static final int VK_NUMPAD3        = 0x63;
  170.     public static final int VK_NUMPAD4        = 0x64;
  171.     public static final int VK_NUMPAD5        = 0x65;
  172.     public static final int VK_NUMPAD6        = 0x66;
  173.     public static final int VK_NUMPAD7        = 0x67;
  174.     public static final int VK_NUMPAD8        = 0x68;
  175.     public static final int VK_NUMPAD9        = 0x69;
  176.     public static final int VK_MULTIPLY       = 0x6A;
  177.     public static final int VK_ADD            = 0x6B;
  178.     public static final int VK_SEPARATER      = 0x6C;
  179.     public static final int VK_SUBTRACT       = 0x6D;
  180.     public static final int VK_DECIMAL        = 0x6E;
  181.     public static final int VK_DIVIDE         = 0x6F;
  182.     public static final int VK_F1             = 0x70;
  183.     public static final int VK_F2             = 0x71;
  184.     public static final int VK_F3             = 0x72;
  185.     public static final int VK_F4             = 0x73;
  186.     public static final int VK_F5             = 0x74;
  187.     public static final int VK_F6             = 0x75;
  188.     public static final int VK_F7             = 0x76;
  189.     public static final int VK_F8             = 0x77;
  190.     public static final int VK_F9             = 0x78;
  191.     public static final int VK_F10            = 0x79;
  192.     public static final int VK_F11            = 0x7A;
  193.     public static final int VK_F12            = 0x7B;
  194.     public static final int VK_DELETE         = 0x7F; /* ASCII DEL */
  195.     public static final int VK_NUM_LOCK       = 0x90;
  196.     public static final int VK_SCROLL_LOCK    = 0x91;
  197.  
  198.     public static final int VK_PRINTSCREEN    = 0x9A;
  199.     public static final int VK_INSERT         = 0x9B;
  200.     public static final int VK_HELP           = 0x9C;
  201.     public static final int VK_META           = 0x9D;
  202.  
  203.     public static final int VK_BACK_QUOTE     = 0xC0;
  204.     public static final int VK_QUOTE          = 0xDE;
  205.  
  206.     /**  for KeyPad cursor arrow keys */
  207.     public static final int VK_KP_UP          = 0xE0;
  208.     public static final int VK_KP_DOWN        = 0xE1;
  209.     public static final int VK_KP_LEFT        = 0xE2;
  210.     public static final int VK_KP_RIGHT       = 0xE3;
  211.     
  212.     /* For European keyboards */
  213.     public static final int VK_DEAD_GRAVE               = 0x80;
  214.     public static final int VK_DEAD_ACUTE               = 0x81;
  215.     public static final int VK_DEAD_CIRCUMFLEX          = 0x82;
  216.     public static final int VK_DEAD_TILDE               = 0x83;
  217.     public static final int VK_DEAD_MACRON              = 0x84;
  218.     public static final int VK_DEAD_BREVE               = 0x85;
  219.     public static final int VK_DEAD_ABOVEDOT            = 0x86;
  220.     public static final int VK_DEAD_DIAERESIS           = 0x87;
  221.     public static final int VK_DEAD_ABOVERING           = 0x88;
  222.     public static final int VK_DEAD_DOUBLEACUTE         = 0x89;
  223.     public static final int VK_DEAD_CARON               = 0x8a;
  224.     public static final int VK_DEAD_CEDILLA             = 0x8b;
  225.     public static final int VK_DEAD_OGONEK              = 0x8c;
  226.     public static final int VK_DEAD_IOTA                = 0x8d;
  227.     public static final int VK_DEAD_VOICED_SOUND        = 0x8e;
  228.     public static final int VK_DEAD_SEMIVOICED_SOUND    = 0x8f;
  229.  
  230.     public static final int VK_AMPERSAND                = 0x96;
  231.     public static final int VK_ASTERISK                 = 0x97;
  232.     public static final int VK_QUOTEDBL                 = 0x98;
  233.     public static final int VK_LESS                     = 0x99;
  234.  
  235.     public static final int VK_GREATER                  = 0xa0;
  236.     public static final int VK_BRACELEFT                = 0xa1;
  237.     public static final int VK_BRACERIGHT               = 0xa2;
  238.  
  239.     /* for Asian Keyboards */
  240.     public static final int VK_FINAL          = 0x18;
  241.     public static final int VK_CONVERT        = 0x1C;
  242.     public static final int VK_NONCONVERT     = 0x1D;
  243.     public static final int VK_ACCEPT         = 0x1E;
  244.     public static final int VK_MODECHANGE     = 0x1F;
  245.     public static final int VK_KANA           = 0x15;
  246.     public static final int VK_KANJI          = 0x19;
  247.  
  248.     /* for Sun keyboards */
  249.     public static final int VK_CUT            = 0xFFD1;
  250.     public static final int VK_COPY           = 0xFFCD;
  251.     public static final int VK_PASTE          = 0xFFCF;
  252.     public static final int VK_UNDO           = 0xFFCB;
  253.     public static final int VK_AGAIN          = 0xFFC9;
  254.     public static final int VK_FIND           = 0xFFD0;
  255.     public static final int VK_PROPS          = 0xFFCA;
  256.     public static final int VK_STOP           = 0xFFC8;
  257.     
  258.     /**
  259.      * KEY_TYPED events do not have a keyCode value.
  260.      * This value is used, instead.  
  261.      */
  262.     public static final int VK_UNDEFINED      = 0x0;
  263.  
  264.     /**
  265.      * KEY_PRESSED and KEY_RELEASED events which do not map to a
  266.      * valid Unicode character use this for the keyChar value.
  267.      */
  268.     public static final char CHAR_UNDEFINED   = 0x0ffff;
  269.  
  270.     int  keyCode;
  271.     char keyChar;
  272.  
  273.     /*
  274.      * JDK 1.1 serialVersionUID 
  275.      */
  276.      private static final long serialVersionUID = -2352130953028126954L;
  277.  
  278.     /**
  279.      * Constructs a KeyEvent object.
  280.      *
  281.      * @param source    the Component that originated the event
  282.      * @param id        an integer identifying the type of event
  283.      * @param when      a long integer that specifys the time the event occurred
  284.      * @param modifiers the modifier keys down during event 
  285.      *                  (shift, ctrl, alt, meta)
  286.      * @param keyCode   the integer code for an actual key, or VK_UNDEFINED 
  287.      *                  (for a key-typed event)
  288.      * @param keyChar   the Unicode character generated by this event, or 
  289.      *                  CHAR_UNDEFINED (for key-pressed and key-released
  290.      *                  events which do not map to a valid Unicode character)
  291.      */
  292.     public KeyEvent(Component source, int id, long when, int modifiers,
  293.                     int keyCode, char keyChar) {
  294.         super(source, id, when, modifiers);
  295.  
  296.         if (id == KEY_TYPED && keyChar == CHAR_UNDEFINED) {
  297.             throw new IllegalArgumentException("invalid keyChar");
  298.         }
  299.         if (id == KEY_TYPED && keyCode != VK_UNDEFINED) {
  300.             throw new IllegalArgumentException("invalid keyCode");
  301.         }
  302.  
  303.         this.keyCode = keyCode;
  304.         this.keyChar = keyChar;
  305.     }
  306.  
  307.     /*
  308.      * @deprecated, as of JDK1.1 - Do NOT USE; will be removed in 1.1.1.
  309.      */
  310.     public KeyEvent(Component source, int id, long when, int modifiers,
  311.                     int keyCode) {
  312.         this(source, id, when, modifiers, keyCode, (char)keyCode);
  313.     }
  314.  
  315.     /**
  316.      * Returns the integer key-code associated with the key in this event.
  317.      * 
  318.      * @return the integer code for an actual key on the keyboard. 
  319.      *         (For KEY_TYPED events, keyCode is VK_UNDEFINED.)
  320.      */
  321.     public int getKeyCode() {
  322.         return keyCode;
  323.     }
  324.  
  325.     /**
  326.      * Set the keyCode value to indicate a physical key.
  327.      *
  328.      * @param keyCode an integer corresponding to an actual key on the keyboard.
  329.      */
  330.     public void setKeyCode(int keyCode) {
  331.         this.keyCode = keyCode;
  332.     }
  333.  
  334.     /**
  335.      * Set the keyChar value to indicate a logical character.
  336.      *
  337.      * @param keyChar a char corresponding to to the combination of keystrokes
  338.      *                that make up this event.
  339.      */
  340.     public void setKeyChar(char keyChar) {
  341.         this.keyChar = keyChar;
  342.     }
  343.  
  344.     /**
  345.      * Set the modifiers to indicate additional keys that were held down
  346.      * (shift, ctrl, alt, meta) defined as part of InputEvent.
  347.      *
  348.      * @param modifiers an integer combination of the modifier constants.
  349.      *
  350.      * @see InputEvent
  351.      */
  352.     public void setModifiers(int modifiers) {
  353.         this.modifiers = modifiers;
  354.     }
  355.  
  356.     /**
  357.      * Returns the character associated with the key in this event.
  358.      * For example, the key-typed event for shift + "a" returns the 
  359.      * value for "A".
  360.      *
  361.      * @return the Unicode character defined for this key event.
  362.      *         If no valid Unicode character exists for this key event, 
  363.      *         keyChar is CHAR_UNDEFINED.
  364.      */
  365.     public char getKeyChar() {
  366.         return keyChar;
  367.     }
  368.  
  369.     /**
  370.      * Returns a String describing the keyCode, such as "HOME", "F1" or "A".
  371.      * These strings can be localized by changing the awt.properties file.
  372.      *
  373.      * @return string a text description for a physical key, identified by
  374.      *                its keyCode
  375.      */
  376.     public static String getKeyText(int keyCode) {
  377.         if (keyCode >= VK_0 && keyCode <= VK_9 || 
  378.             keyCode >= VK_A && keyCode <= VK_Z) {
  379.             return String.valueOf((char)keyCode);
  380.         }
  381.  
  382.         // Check for other ASCII keyCodes.
  383.         int index = ",./;=[\\]".indexOf(keyCode);
  384.         if (index >= 0) {
  385.             return String.valueOf((char)keyCode);
  386.         }
  387.     
  388.         switch(keyCode) {
  389.           case VK_ENTER: return Toolkit.getProperty("AWT.enter", "Enter");
  390.           case VK_BACK_SPACE: return Toolkit.getProperty("AWT.backSpace", "Backspace");
  391.           case VK_TAB: return Toolkit.getProperty("AWT.tab", "Tab");
  392.           case VK_CANCEL: return Toolkit.getProperty("AWT.cancel", "Cancel");
  393.           case VK_CLEAR: return Toolkit.getProperty("AWT.clear", "Clear");
  394.           case VK_SHIFT: return Toolkit.getProperty("AWT.shift", "Shift");
  395.           case VK_CONTROL: return Toolkit.getProperty("AWT.control", "Control");
  396.           case VK_ALT: return Toolkit.getProperty("AWT.alt", "Alt");
  397.           case VK_PAUSE: return Toolkit.getProperty("AWT.pause", "Pause");
  398.           case VK_CAPS_LOCK: return Toolkit.getProperty("AWT.capsLock", "Caps Lock");
  399.           case VK_ESCAPE: return Toolkit.getProperty("AWT.escape", "Escape");
  400.           case VK_SPACE: return Toolkit.getProperty("AWT.space", "Space");
  401.           case VK_PAGE_UP: return Toolkit.getProperty("AWT.pgup", "Page Up");
  402.           case VK_PAGE_DOWN: return Toolkit.getProperty("AWT.pgdn", "Page Down");
  403.           case VK_END: return Toolkit.getProperty("AWT.end", "End");
  404.           case VK_HOME: return Toolkit.getProperty("AWT.home", "Home");
  405.           case VK_LEFT: return Toolkit.getProperty("AWT.left", "Left");
  406.           case VK_UP: return Toolkit.getProperty("AWT.up", "Up");
  407.           case VK_RIGHT: return Toolkit.getProperty("AWT.right", "Right");
  408.           case VK_DOWN: return Toolkit.getProperty("AWT.down", "Down");
  409.  
  410.           case VK_KP_LEFT: return Toolkit.getProperty("AWT.left", "Left");
  411.           case VK_KP_UP: return Toolkit.getProperty("AWT.up", "Up");
  412.           case VK_KP_RIGHT: return Toolkit.getProperty("AWT.right", "Right");
  413.           case VK_KP_DOWN: return Toolkit.getProperty("AWT.down", "Down");
  414.  
  415.           case VK_MULTIPLY: return Toolkit.getProperty("AWT.multiply", "NumPad *");
  416.           case VK_ADD: return Toolkit.getProperty("AWT.add", "NumPad +");
  417.           case VK_SEPARATER: return Toolkit.getProperty("AWT.separater", "NumPad ,");
  418.           case VK_SUBTRACT: return Toolkit.getProperty("AWT.subtract", "NumPad -");
  419.           case VK_DECIMAL: return Toolkit.getProperty("AWT.decimal", "NumPad .");
  420.           case VK_DIVIDE: return Toolkit.getProperty("AWT.divide", "NumPad /");
  421.  
  422.           case VK_F1: return Toolkit.getProperty("AWT.f1", "F1");
  423.           case VK_F2: return Toolkit.getProperty("AWT.f2", "F2");
  424.           case VK_F3: return Toolkit.getProperty("AWT.f3", "F3");
  425.           case VK_F4: return Toolkit.getProperty("AWT.f4", "F4");
  426.           case VK_F5: return Toolkit.getProperty("AWT.f5", "F5");
  427.           case VK_F6: return Toolkit.getProperty("AWT.f6", "F6");
  428.           case VK_F7: return Toolkit.getProperty("AWT.f7", "F7");
  429.           case VK_F8: return Toolkit.getProperty("AWT.f8", "F8");
  430.           case VK_F9: return Toolkit.getProperty("AWT.f9", "F9");
  431.           case VK_F10: return Toolkit.getProperty("AWT.f10", "F10");
  432.           case VK_F11: return Toolkit.getProperty("AWT.f11", "F11");
  433.           case VK_F12: return Toolkit.getProperty("AWT.f12", "F12");
  434.           case VK_DELETE: return Toolkit.getProperty("AWT.delete", "Delete");
  435.           case VK_NUM_LOCK: return Toolkit.getProperty("AWT.numLock", "Num Lock");
  436.           case VK_SCROLL_LOCK: return Toolkit.getProperty("AWT.scrollLock", "Scroll Lock");
  437.           case VK_PRINTSCREEN: return Toolkit.getProperty("AWT.printScreen", "Print Screen");
  438.           case VK_INSERT: return Toolkit.getProperty("AWT.insert", "Insert");
  439.           case VK_HELP: return Toolkit.getProperty("AWT.help", "Help");
  440.           case VK_META: return Toolkit.getProperty("AWT.meta", "Meta");
  441.           case VK_BACK_QUOTE: return Toolkit.getProperty("AWT.backQuote", "Back Quote");
  442.           case VK_QUOTE: return Toolkit.getProperty("AWT.quote", "Quote");
  443.              
  444.           case VK_FINAL: return Toolkit.getProperty("AWT.final", "Final");
  445.           case VK_CONVERT: return Toolkit.getProperty("AWT.convert", "Convert");
  446.           case VK_NONCONVERT: return Toolkit.getProperty("AWT.noconvert", "No Convert");
  447.           case VK_ACCEPT: return Toolkit.getProperty("AWT.accept", "Accept");
  448.           case VK_MODECHANGE: return Toolkit.getProperty("AWT.modechange", "Mode Change");
  449.           case VK_KANA: return Toolkit.getProperty("AWT.kana", "Kana");
  450.       case VK_KANJI: return Toolkit.getProperty("AWT.kanji", "Kanji");
  451.  
  452.           case VK_DEAD_GRAVE: return Toolkit.getProperty("AWT.deadGrave", "Dead Grave");
  453.           case VK_DEAD_ACUTE: return Toolkit.getProperty("AWT.deadAcute", "Dead Acute");
  454.           case VK_DEAD_CIRCUMFLEX: return Toolkit.getProperty("AWT.deadCircumflex", "Dead Circumflex");
  455.           case VK_DEAD_TILDE: return Toolkit.getProperty("AWT.deadTilde", "Dead Tilde");
  456.           case VK_DEAD_MACRON: return Toolkit.getProperty("AWT.deadMacron", "Dead Macron");
  457.           case VK_DEAD_BREVE: return Toolkit.getProperty("AWT.deadBreve", "Dead Breve");
  458.           case VK_DEAD_ABOVEDOT: return Toolkit.getProperty("AWT.deadAboveDot", "Dead Above Dot");
  459.           case VK_DEAD_DIAERESIS: return Toolkit.getProperty("AWT.deadDiaeresis", "Dead Diaeresis");
  460.           case VK_DEAD_ABOVERING: return Toolkit.getProperty("AWT.deadAboveRing", "Dead Above Ring");
  461.           case VK_DEAD_DOUBLEACUTE: return Toolkit.getProperty("AWT.deadDoubleAcute", "Dead Double Acute");
  462.           case VK_DEAD_CARON: return Toolkit.getProperty("AWT.deadCaron", "Dead Caron");
  463.           case VK_DEAD_CEDILLA: return Toolkit.getProperty("AWT.deadCedilla", "Dead Cedilla");
  464.           case VK_DEAD_OGONEK: return Toolkit.getProperty("AWT.deadOgonek", "Dead Ogonek");
  465.           case VK_DEAD_IOTA: return Toolkit.getProperty("AWT.deadIota", "Dead Iota");
  466.           case VK_DEAD_VOICED_SOUND: return Toolkit.getProperty("AWT.deadVoicedSound", "Dead Voiced Sound");
  467.           case VK_DEAD_SEMIVOICED_SOUND: return Toolkit.getProperty("AWT.deadSemivoicedSound", "Dead Semivoiced Sound");
  468.           case VK_AMPERSAND: return Toolkit.getProperty("AWT.ampersand", "Ampersand");
  469.           case VK_ASTERISK: return Toolkit.getProperty("AWT.asterisk", "Asterisk");
  470.           case VK_QUOTEDBL: return Toolkit.getProperty("AWT.quoteDbl", "Quote Dbl");
  471.           case VK_LESS: return Toolkit.getProperty("AWT.Less", "Less");
  472.           case VK_GREATER: return Toolkit.getProperty("AWT.greater", "Greater");
  473.           case VK_BRACELEFT: return Toolkit.getProperty("AWT.braceLeft", "Brace Left");
  474.           case VK_BRACERIGHT: return Toolkit.getProperty("AWT.braceRight", "Brace Right");
  475.           case VK_AGAIN: return Toolkit.getProperty("AWT.again", "Again");
  476.           case VK_UNDO: return Toolkit.getProperty("AWT.undo", "Undo");
  477.           case VK_COPY: return Toolkit.getProperty("AWT.copy", "Copy");
  478.           case VK_PASTE: return Toolkit.getProperty("AWT.paste", "Paste");
  479.           case VK_CUT: return Toolkit.getProperty("AWT.cut", "Cut");
  480.           case VK_FIND: return Toolkit.getProperty("AWT.find", "Find");
  481.           case VK_PROPS: return Toolkit.getProperty("AWT.props", "Props");
  482.           case VK_STOP: return Toolkit.getProperty("AWT.stop", "Stop");
  483.         }
  484.  
  485.         if (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9) {
  486.             String numpad = Toolkit.getProperty("AWT.numpad", "NumPad");
  487.         char c = (char)(keyCode - VK_NUMPAD0 + '0');
  488.             return numpad + "-" + c;
  489.         }
  490.  
  491.         String unknown = Toolkit.getProperty("AWT.unknown", "Unknown keyCode");
  492.         return unknown + ": 0x" + Integer.toString(keyCode, 16);
  493.     }
  494.  
  495.     /**
  496.      * Returns a String describing the modifier key(s), such as "Shift",
  497.      * or "Ctrl+Shift".  These strings can be localized by changing the 
  498.      * awt.properties file.
  499.      *
  500.      * @return string a text description of the combination of modifier
  501.      *                keys that were held down during the event
  502.      */
  503.     public static String getKeyModifiersText(int modifiers) {
  504.         StringBuffer buf = new StringBuffer();
  505.         if ((modifiers & InputEvent.META_MASK) != 0) {
  506.             buf.append(Toolkit.getProperty("AWT.meta", "Meta"));
  507.             buf.append("+");
  508.         }
  509.         if ((modifiers & InputEvent.CTRL_MASK) != 0) {
  510.             buf.append(Toolkit.getProperty("AWT.control", "Ctrl"));
  511.             buf.append("+");
  512.         }
  513.         if ((modifiers & InputEvent.ALT_MASK) != 0) {
  514.             buf.append(Toolkit.getProperty("AWT.alt", "Alt"));
  515.             buf.append("+");
  516.         }
  517.         if ((modifiers & InputEvent.SHIFT_MASK) != 0) {
  518.             buf.append(Toolkit.getProperty("AWT.shift", "Shift"));
  519.             buf.append("+");
  520.         }
  521.         if (buf.length() > 0) {
  522.             buf.setLength(buf.length()-1); // remove trailing '+'
  523.         }
  524.         return buf.toString();
  525.     }
  526.  
  527.     /** Returns whether or not the key in this event is an "action" key,
  528.      *  as defined in Event.java.
  529.      *
  530.      * @return boolean value, true if the key is an "action" key
  531.      *
  532.      * @see Event
  533.      */
  534.     public boolean isActionKey() {
  535.         switch (keyCode) {
  536.           case VK_HOME:
  537.           case VK_END:
  538.           case VK_PAGE_UP:
  539.           case VK_PAGE_DOWN:
  540.           case VK_UP:
  541.           case VK_DOWN:
  542.           case VK_LEFT:
  543.           case VK_RIGHT:
  544.  
  545.       case VK_KP_LEFT: 
  546.       case VK_KP_UP: 
  547.       case VK_KP_RIGHT: 
  548.       case VK_KP_DOWN: 
  549.  
  550.           case VK_F1:
  551.           case VK_F2:
  552.           case VK_F3:
  553.           case VK_F4:
  554.           case VK_F5:
  555.           case VK_F6:
  556.           case VK_F7:
  557.           case VK_F8:
  558.           case VK_F9:
  559.           case VK_F10:
  560.           case VK_F11:
  561.           case VK_F12:
  562.           case VK_PRINTSCREEN:
  563.           case VK_SCROLL_LOCK:
  564.           case VK_CAPS_LOCK:
  565.           case VK_NUM_LOCK:
  566.           case VK_PAUSE:
  567.           case VK_INSERT:
  568.  
  569.           case VK_AGAIN:
  570.           case VK_UNDO:
  571.           case VK_COPY:
  572.           case VK_PASTE:
  573.           case VK_CUT:
  574.           case VK_FIND:
  575.           case VK_PROPS:
  576.           case VK_STOP:
  577.               return true;
  578.         }
  579.         return false;
  580.     }
  581.  
  582.     /**
  583.      * Returns a parameter string identifying this event.
  584.      * This method is useful for event-logging and for debugging.
  585.      *
  586.      * @return a string identifying the event and its attributes
  587.      */
  588.     public String paramString() {
  589.         String typeStr;
  590.         switch(id) {
  591.           case KEY_PRESSED:
  592.               typeStr = "KEY_PRESSED";
  593.               break;
  594.           case KEY_RELEASED:
  595.               typeStr = "KEY_RELEASED";
  596.               break;
  597.           case KEY_TYPED:
  598.               typeStr = "KEY_TYPED";
  599.               break;
  600.           default:
  601.               typeStr = "unknown type";
  602.         }
  603.  
  604.         String str = typeStr + ",keyCode=" + keyCode;
  605.         if (isActionKey() || keyCode == VK_ENTER || keyCode == VK_BACK_SPACE || 
  606.         keyCode == VK_TAB || keyCode == VK_ESCAPE || keyCode == VK_DELETE ||
  607.         (keyCode >= VK_NUMPAD0 && keyCode <= VK_NUMPAD9)) {
  608.             str += "," + getKeyText(keyCode);
  609.     } else if (keyChar == '\n' || keyChar == '\b' ||
  610.         keyChar == '\t' || keyChar == VK_ESCAPE || keyChar == VK_DELETE) {
  611.             str += "," + getKeyText(keyChar);
  612.         } else {
  613.             str += ",keyChar='" + keyChar + "'";
  614.         }
  615.         if (modifiers > 0) {
  616.             str += ",modifiers=" + getKeyModifiersText(modifiers);
  617.         }
  618.         return str;
  619.     }
  620.  
  621. }
  622.