Class KeyEvent

java.lang.Object
org.jline.terminal.KeyEvent

public class KeyEvent extends 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 Details

  • Method Details

    • getType

      public KeyEvent.Type getType()
    • getCharacter

      public char getCharacter()
    • getArrow

      public KeyEvent.Arrow getArrow()
    • getSpecial

      public KeyEvent.Special getSpecial()
    • 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()
    • getModifiers

      public EnumSet<KeyEvent.Modifier> getModifiers()
    • getRawSequence

      public String getRawSequence()
    • hasModifier

      public boolean hasModifier(KeyEvent.Modifier modifier)
    • 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 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 String toString()
      Overrides:
      toString in class Object