Class KeyEvent


  • public class KeyEvent
    extends java.lang.Object
    Represents a keyboard event in a terminal.

    The KeyEvent class encapsulates information about keyboard actions in a terminal, including the type of key pressed, any modifier keys that were held, and the raw sequence that was received from the terminal.

    Key events include:

    • Character - A printable character was typed
    • Arrow - An arrow key was pressed (Up, Down, Left, Right)
    • Function - A function key was pressed (F1-F35)
    • Special - A special key was pressed (Enter, Tab, Escape, etc.)
    • Keypad - A keypad key was pressed
    • Media - A media key was pressed
    • ModifierKey - A modifier key was pressed/released as its own event
    • Unknown - An unrecognized key sequence
    • Constructor Detail

      • KeyEvent

        public KeyEvent​(char character,
                        java.util.EnumSet<KeyEvent.Modifier> modifiers,
                        java.lang.String rawSequence)
        Creates a character key event.
      • KeyEvent

        public KeyEvent​(KeyEvent.Arrow arrow,
                        java.util.EnumSet<KeyEvent.Modifier> modifiers,
                        java.lang.String rawSequence)
        Creates an arrow key event.
      • KeyEvent

        public KeyEvent​(KeyEvent.Special special,
                        java.util.EnumSet<KeyEvent.Modifier> modifiers,
                        java.lang.String rawSequence)
        Creates a special key event.
      • KeyEvent

        public KeyEvent​(int functionKey,
                        java.util.EnumSet<KeyEvent.Modifier> modifiers,
                        java.lang.String rawSequence)
        Creates a function key event.
      • KeyEvent

        public KeyEvent​(java.lang.String rawSequence)
        Creates an unknown key event.
      • KeyEvent

        public KeyEvent​(KeyEvent.Type type,
                        char character,
                        KeyEvent.Arrow arrow,
                        KeyEvent.Special special,
                        int functionKey,
                        java.util.EnumSet<KeyEvent.Modifier> modifiers,
                        java.lang.String rawSequence,
                        KeyEvent.EventType eventType,
                        int keyCode,
                        int shiftedKeyCode,
                        int baseLayoutKeyCode,
                        java.lang.String associatedText)
        Backward-compatible constructor without keypad/media/modifier key fields.
    • Method Detail

      • getCharacter

        public char getCharacter()
      • getKeypad

        public KeyEvent.Keypad getKeypad()
        Returns the keypad key, or null if this is not a keypad event.
      • getMediaKey

        public KeyEvent.MediaKey getMediaKey()
        Returns the media key, or null if this is not a media event.
      • getModKey

        public KeyEvent.ModKey getModKey()
        Returns the modifier key, or null if this is not a modifier key event.
      • getFunctionKey

        public int getFunctionKey()
      • getRawSequence

        public java.lang.String getRawSequence()
      • getEventType

        public KeyEvent.EventType getEventType()
        Returns the event type (press, repeat, or release). Only meaningful when the Kitty Keyboard Protocol is active with the FLAG_REPORT_EVENTS flag enabled.
        Returns:
        the event type, defaults to KeyEvent.EventType.Press
      • getKeyCode

        public int getKeyCode()
        Returns the Unicode key code as reported by the Kitty Keyboard Protocol. This is the primary key identifier ? always the lowercase/unshifted codepoint for letter keys.
        Returns:
        the key code, or 0 if not from a kitty protocol sequence
      • getShiftedKeyCode

        public int getShiftedKeyCode()
        Returns the shifted variant key code. Only present when the Kitty Keyboard Protocol is active with the FLAG_REPORT_ALTERNATES flag and Shift is held.
        Returns:
        the shifted key code, or 0 if absent
      • getBaseLayoutKeyCode

        public int getBaseLayoutKeyCode()
        Returns the base layout key code (the key on a US keyboard layout). Only present when the Kitty Keyboard Protocol is active with the FLAG_REPORT_ALTERNATES flag.
        Returns:
        the base layout key code, or 0 if absent
      • getAssociatedText

        public java.lang.String getAssociatedText()
        Returns the associated text reported by the terminal. Only present when the Kitty Keyboard Protocol is active with the FLAG_REPORT_TEXT flag.
        Returns:
        the associated text, or null if absent
      • toString

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