Class KeyCodes


  • public class KeyCodes
    extends java.lang.Object
    Contains the native key codes previously defined in KeyboardListener. When converting keyboard listener instances, developers can use the following static import to access these constants:
     import static com.google.gwt.event.dom.client.KeyCodes.*; 
    These constants are defined with an int data type in order to be compatible with the constants defined in KeyboardListener.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int KEY_A
      Key code for A
      static int KEY_ALT
      Alt key code.
      static int KEY_B
      Key code for B
      static int KEY_BACKSPACE
      Backspace key code.
      static int KEY_C
      Key code for C
      static int KEY_CAPS_LOCK
      Key code for caps lock key
      static int KEY_CLOSE_BRACKET
      Key code for close square bracket, ].
      static int KEY_CONTEXT_MENU
      Key code for context menu key.
      static int KEY_CTRL
      Control key code.
      static int KEY_D
      Key code for D
      static int KEY_DELETE
      Delete key code (also numeric keypad delete).
      static int KEY_DOWN
      Down arrow code (Also numeric keypad down).
      static int KEY_E
      Key code for E
      static int KEY_EIGHT
      Key code number 8
      static int KEY_END
      End key code (Also numeric keypad south west).
      static int KEY_ENTER
      Enter key code.
      static int KEY_ESCAPE
      Escape key code.
      static int KEY_F
      Key code for F
      static int KEY_F1
      Key code for F1
      static int KEY_F10
      Key code for F10
      static int KEY_F11
      Key code for F11
      static int KEY_F12
      Key code for F12
      static int KEY_F2
      Key code for F2
      static int KEY_F3
      Key code for F3
      static int KEY_F4
      Key code for F4
      static int KEY_F5
      Key code for F5
      static int KEY_F6
      Key code for F6
      static int KEY_F7
      Key code for F7
      static int KEY_F8
      Key code for F8
      static int KEY_F9
      Key code for F9
      static int KEY_FIRST_MEDIA_KEY
      Key code for first OS specific media key (like volume).
      static int KEY_FIVE
      Key code number 5
      static int KEY_FOUR
      Key code number 4
      static int KEY_G
      Key code for G
      static int KEY_H
      Key code for H
      static int KEY_HOME
      Home key code (Also numeric keypad north west).
      static int KEY_I
      Key code for I
      static int KEY_INSERT
      Key code for insert key (Also numeric keyboard insert).
      static int KEY_J
      Key code for J
      static int KEY_K
      Key code for K
      static int KEY_L
      Key code for L
      static int KEY_LAST_MEDIA_KEY
      Key code for last OS specific media key (like volume).
      static int KEY_LEFT
      Left key code (Also numeric keypad west).
      static int KEY_M
      Key code for M
      static int KEY_MAC_ENTER
      Key code for Mac enter key
      static int KEY_MAC_FF_META
      Key code for KEY_WIN_KEY_LEFT_META that Firefox fires for the meta key.
      static int KEY_N
      Key code for N
      static int KEY_NINE
      Key code number 9
      static int KEY_NUM_CENTER
      Key code for insert key (Also num lock on FF,Safari Mac).
      static int KEY_NUM_DIVISION
      Key code for division on numeric keyboard
      static int KEY_NUM_EIGHT
      Key code for number 8 on numeric keyboard
      static int KEY_NUM_FIVE
      Key code for number 5 on numeric keyboard
      static int KEY_NUM_FOUR
      Key code for number 4 on numeric keyboard
      static int KEY_NUM_MINUS
      Key code for minus on numeric keyboard
      static int KEY_NUM_MULTIPLY
      Key code for multiply on numeric keyboard
      static int KEY_NUM_NINE
      Key code for number 9 on numeric keyboard
      static int KEY_NUM_ONE
      Key code for number 1 on numeric keyboard
      static int KEY_NUM_PERIOD
      Key code for period on numeric keyboard
      static int KEY_NUM_PLUS
      Key code for plus on numeric keyboard
      static int KEY_NUM_SEVEN
      Key code for number 7 on numeric keyboard
      static int KEY_NUM_SIX
      Key code for number 6 on numeric keyboard
      static int KEY_NUM_THREE
      Key code for number 3 on numeric keyboard
      static int KEY_NUM_TWO
      Key code for number 2 on numeric keyboard
      static int KEY_NUM_ZERO
      Key code for number 0 on numeric keyboard
      static int KEY_NUMLOCK
      Key code for num lock.
      static int KEY_O
      Key code for O
      static int KEY_ONE
      Key code number 1
      static int KEY_OPEN_BRACKET
      Key code for open square bracket, [.
      static int KEY_P
      Key code for P
      static int KEY_PAGEDOWN
      Page down key code (Also numeric keypad south east).
      static int KEY_PAGEUP
      Page up key code (Also numeric keypad north east).
      static int KEY_PAUSE
      Key code for pause key
      static int KEY_PRINT_SCREEN
      Key code for print key
      static int KEY_Q
      Key code for Q
      static int KEY_R
      Key code for R
      static int KEY_RIGHT
      Right arrow key code (Also numeric keypad east).
      static int KEY_S
      Key code for S
      static int KEY_SCROLL_LOCK
      Key code for scroll lock.
      static int KEY_SEVEN
      Key code number 7
      static int KEY_SHIFT
      Shift key code.
      static int KEY_SIX
      Key code number 6
      static int KEY_SPACE
      Key code for space
      static int KEY_T
      Key code for T
      static int KEY_TAB
      Tab key code.
      static int KEY_THREE
      Key code number 3
      static int KEY_TWO
      Key code number 2
      static int KEY_U
      Key code for U
      static int KEY_UP
      Up Arrow key code (Also numeric keypad north).
      static int KEY_V
      Key code for V
      static int KEY_W
      Key code for W
      static int KEY_WIN_IME
      Key code for IME.
      static int KEY_WIN_KEY
      Key code for left windows key.
      static int KEY_WIN_KEY_FF_LINUX
      Key code for Windows key on Firefox Linux
      static int KEY_WIN_KEY_LEFT_META
      Key code for left windows key or meta.
      static int KEY_WIN_KEY_RIGHT
      Key code for right windows key.
      static int KEY_X
      Key code for X
      static int KEY_Y
      Key code for Y
      static int KEY_Z
      Key code for Z
      static int KEY_ZERO
      Key code number 0
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean isArrowKey​(int code)
      Determines if a key code is an arrow key.
      static int maybeSwapArrowKeysForRtl​(int code, boolean isRtl)
      Update arrow keys for left and right based on current locale.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • isArrowKey

        public static boolean isArrowKey​(int code)
        Determines if a key code is an arrow key.
      • maybeSwapArrowKeysForRtl

        public static int maybeSwapArrowKeysForRtl​(int code,
                                                   boolean isRtl)
        Update arrow keys for left and right based on current locale.

        Note: this method is used internally by built-in GWT widgets but could be renamed/refactored without notice.

        This method simplifies RTL handling in your code:

         int keyCode = KeyCodes.maybeSwapArrowKeysForRtl(event.getKeyCode(),
           LocaleInfo.getCurrentLocale().isRTL());
         switch (keyCode) {
           case KeyCodes.KEY_LEFT:
             ... // start of the line, no special RTL handling
             break;
           case KeyCodes.KEY_RIGHT:
             ... // end of the line, no special RTL handling
             break;
           ...
           }