Class KeyEvent


  • public final class KeyEvent
    extends java.lang.Object
    An immutable, normalized key event. The terminal driver translates raw escape sequences into these.
    • Constructor Summary

      Constructors 
      Constructor Description
      KeyEvent​(Key code, char ch, boolean ctrl, boolean alt, boolean shift)
      Creates a key event.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean alt()  
      char ch()  
      static KeyEvent character​(char ch)
      Creates a printable character event with no modifiers.
      static KeyEvent character​(char ch, boolean ctrl, boolean alt, boolean shift)
      Creates a printable character event with modifiers.
      Key code()  
      boolean ctrl()  
      boolean is​(Key k)  
      boolean shift()  
      static KeyEvent special​(Key code)
      Creates a non-printable key event with no modifiers.
      static KeyEvent special​(Key code, boolean ctrl, boolean alt, boolean shift)
      Creates a non-printable key event with modifiers.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • KeyEvent

        public KeyEvent​(Key code,
                        char ch,
                        boolean ctrl,
                        boolean alt,
                        boolean shift)
        Creates a key event.
        Parameters:
        code - the logical key
        ch - the character, valid when code is CHAR
        ctrl - whether the Ctrl modifier is held
        alt - whether the Alt modifier is held
        shift - whether the Shift modifier is held
    • Method Detail

      • special

        public static KeyEvent special​(Key code)
        Creates a non-printable key event with no modifiers.
        Parameters:
        code - the logical key
        Returns:
        the key event
      • special

        public static KeyEvent special​(Key code,
                                       boolean ctrl,
                                       boolean alt,
                                       boolean shift)
        Creates a non-printable key event with modifiers.
        Parameters:
        code - the logical key
        ctrl - whether the Ctrl modifier is held
        alt - whether the Alt modifier is held
        shift - whether the Shift modifier is held
        Returns:
        the key event
      • character

        public static KeyEvent character​(char ch)
        Creates a printable character event with no modifiers.
        Parameters:
        ch - the character
        Returns:
        the key event
      • character

        public static KeyEvent character​(char ch,
                                         boolean ctrl,
                                         boolean alt,
                                         boolean shift)
        Creates a printable character event with modifiers.
        Parameters:
        ch - the character
        ctrl - whether the Ctrl modifier is held
        alt - whether the Alt modifier is held
        shift - whether the Shift modifier is held
        Returns:
        the key event
      • code

        public Key code()
        Returns:
        the logical key
      • ch

        public char ch()
        Returns:
        the character, valid when code() == CHAR
      • ctrl

        public boolean ctrl()
        Returns:
        true when the Ctrl modifier is held
      • alt

        public boolean alt()
        Returns:
        true when the Alt modifier is held
      • shift

        public boolean shift()
        Returns:
        true when the Shift modifier is held
      • is

        public boolean is​(Key k)
        Parameters:
        k - the key to compare against
        Returns:
        true when this event's logical key equals k
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object