Class KeyEvent2


  • public class KeyEvent2
    extends java.lang.Object
    Represents a pressed or released key.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int ALT
      The mask for "shift".
      static int ALT_GRAPH
      The mask for "alt_graph".
      static int CTRL
      The mask for "ctrl".
      static int MASK
      The mask for all used modifiers.
      static int META
      The mask for "meta".
      static int NONE
      The mask for "no modifier".
      static int SHIFT
      The mask for "shift".
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyEvent2​(int keyCode, char keyChar, int modifiers)
      Creates a new instance.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int convertModifiers​(int modifiers)
      Converts old-style modifiers into the current format.
      boolean equals​(@Nullable java.lang.Object obj)  
      boolean equalsKeyCode​(@NotNull KeyEvent2 keyEvent)
      Returns whether this key event matches the same key code as another key event.
      char getKeyChar()
      Returns the key as a char.
      int getKeyCode()
      Returns the key code.
      int getModifiers()
      Returns the modifiers.
      int hashCode()  
      static @NotNull java.lang.String modifiersToString​(int modifiers)
      Converts modifiers to string representation.
      static int stringToModifiers​(@NotNull java.lang.String modifiers)
      Converts a string representation to modifiers.
      @NotNull java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • KeyEvent2

        public KeyEvent2​(int keyCode,
                         char keyChar,
                         int modifiers)
        Creates a new instance.
        Parameters:
        keyCode - the key code
        keyChar - the key as a char
        modifiers - the modifiers
    • Method Detail

      • getKeyCode

        public int getKeyCode()
        Returns the key code. See VK_xxx constants.
        Returns:
        the key code
      • getKeyChar

        public char getKeyChar()
        Returns the key as a char.
        Returns:
        the key as a char
      • getModifiers

        public int getModifiers()
        Returns the modifiers. A combination of ALT, ALT_GRAPH, CTRL, META, and SHIFT.
        Returns:
        the modifiers
      • equalsKeyCode

        public boolean equalsKeyCode​(@NotNull
                                     @NotNull KeyEvent2 keyEvent)
        Returns whether this key event matches the same key code as another key event.
        Parameters:
        keyEvent - the other key event
        Returns:
        whether both instances match the same key code
      • equals

        public boolean equals​(@Nullable
                              @Nullable java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        @NotNull
        public @NotNull java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • convertModifiers

        public static int convertModifiers​(int modifiers)
        Converts old-style modifiers into the current format.
        Parameters:
        modifiers - the old-style modifiers
        Returns:
        the current format
      • modifiersToString

        @NotNull
        public static @NotNull java.lang.String modifiersToString​(int modifiers)
        Converts modifiers to string representation.
        Parameters:
        modifiers - the modifiers
        Returns:
        the string representation
      • stringToModifiers

        public static int stringToModifiers​(@NotNull
                                            @NotNull java.lang.String modifiers)
        Converts a string representation to modifiers. If the string representation is invalid, a warning is printed and the invalid part is ignored.
        Parameters:
        modifiers - the string representation
        Returns:
        the modifiers