Class KeyEvent

    • Method Detail

      • create

        public static KeyEvent create​(short eventType,
                                      Object source,
                                      long when,
                                      int modifiers,
                                      short keyCode,
                                      short keySym,
                                      char keyChar)
      • getKeyCode

        public final short getKeyCode()
        Returns the virtual key code using a fixed mapping to the US keyboard layout.

        In contrast to key symbol, key code uses a fixed US keyboard layout and therefore is keyboard layout independent.

        E.g. virtual key code VK_Y denotes the same physical key regardless whether keyboard layout QWERTY or QWERTZ is active. The key symbol of the former is VK_Y, where the latter produces VK_Y.

        See Also:
        getKeyChar(), getKeySymbol()
      • getEventTypeString

        public static String getEventTypeString​(short type)
      • utf16ToVKey

        public static short utf16ToVKey​(char keyChar)
        Parameters:
        keyChar - UTF16 value to map. It is expected that the incoming keyChar value is unshifted and unmodified, however, lower case a-z is mapped to VK_A - VK_Z.
        Returns:
        KeyEvent virtual key (VK) value.
      • isModifierKey

        public static boolean isModifierKey​(short vKey)
        Returns true if the given virtualKey represents a modifier key, otherwise false.

        A modifier key is one of VK_SHIFT, VK_CONTROL, VK_ALT, VK_ALT_GRAPH, VK_META.

      • getModifierMask

        public static int getModifierMask​(short vKey)
        If vKey is a modifier key, method returns the corresponding modifier mask, otherwise 0.
      • isModifierKey

        public final boolean isModifierKey()
        Returns true if key symbol represents a modifier key, otherwise false.

        See isModifierKey(short) for details.

        Note: Implementation uses a cached value.

      • isActionKey

        public final boolean isActionKey()
        Returns true if key symbol represents a non-printable and non-modifier action key, otherwise false.

        Hence it is the set A of all keys U w/o printable P and w/o modifiers M: A = U - ( P + M )

        See Also:
        isPrintableKey(), isModifierKey()
      • isPrintableKey

        public static boolean isPrintableKey​(short uniChar,
                                             boolean isKeyChar)
        Returns true if given uniChar represents a printable character, i.e. a value other than VK_UNDEFINED and not a control or non-printable private code.

        A printable character is neither a modifier key, nor an action key.

        Otherwise returns false.

        Distinction of key character and virtual key code is made due to unicode collision.

        Parameters:
        uniChar - the UTF-16 unicode value, which maybe a virtual key code or key character.
        isKeyChar - true if uniChar is a key character, otherwise a virtual key code
      • isPrintableKey

        public final boolean isPrintableKey()
        Returns true if key symbol and key char represents a printable character, i.e. a value other than VK_UNDEFINED and not a control or non-printable private code.

        A printable character is neither a modifier key, nor an action key.

        Otherwise returns false.