Package org.jline.terminal
Class KeyEvent
java.lang.Object
org.jline.terminal.KeyEvent
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumDefines arrow key directions.static enumDefines the type of key action for protocols that distinguish press, repeat, and release events (e.g., Kitty Keyboard Protocol).static enumDefines keypad keys reported by the Kitty Keyboard Protocol.static enumDefines media keys reported by the Kitty Keyboard Protocol.static enumDefines modifier keys that can be held during a key event.static enumIdentifies individual modifier keys for standalone key events.static enumDefines special keys.static enumDefines the types of key events that can occur. -
Constructor Summary
ConstructorsConstructorDescriptionKeyEvent(char character, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence) Creates a character key event.KeyEvent(int functionKey, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence) Creates a function key event.Creates an unknown key event.KeyEvent(KeyEvent.Arrow arrow, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence) Creates an arrow key event.KeyEvent(KeyEvent.Special special, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence) Creates a special key event.KeyEvent(KeyEvent.Type type, char character, KeyEvent.Arrow arrow, KeyEvent.Special special, int functionKey, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence, KeyEvent.EventType eventType, int keyCode, int shiftedKeyCode, int baseLayoutKeyCode, String associatedText) Backward-compatible constructor without keypad/media/modifier key fields.KeyEvent(KeyEvent.Type type, char character, KeyEvent.Arrow arrow, KeyEvent.Special special, KeyEvent.Keypad keypad, KeyEvent.MediaKey mediaKey, KeyEvent.ModKey modKey, int functionKey, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence, KeyEvent.EventType eventType, int keyCode, int shiftedKeyCode, int baseLayoutKeyCode, String associatedText) Full constructor with all Kitty Keyboard Protocol fields. -
Method Summary
Modifier and TypeMethodDescriptiongetArrow()Returns the associated text reported by the terminal.intReturns the base layout key code (the key on a US keyboard layout).charReturns the event type (press, repeat, or release).intintReturns the Unicode key code as reported by the Kitty Keyboard Protocol.Returns the keypad key, ornullif this is not a keypad event.Returns the media key, ornullif this is not a media event.Returns the modifier key, ornullif this is not a modifier key event.intReturns the shifted variant key code.getType()booleanhasModifier(KeyEvent.Modifier modifier) toString()
-
Constructor Details
-
KeyEvent
Creates a character key event. -
KeyEvent
Creates an arrow key event. -
KeyEvent
Creates a special key event. -
KeyEvent
Creates a function key event. -
KeyEvent
Creates an unknown key event. -
KeyEvent
public KeyEvent(KeyEvent.Type type, char character, KeyEvent.Arrow arrow, KeyEvent.Special special, int functionKey, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence, KeyEvent.EventType eventType, int keyCode, int shiftedKeyCode, int baseLayoutKeyCode, String associatedText) Backward-compatible constructor without keypad/media/modifier key fields. -
KeyEvent
public KeyEvent(KeyEvent.Type type, char character, KeyEvent.Arrow arrow, KeyEvent.Special special, KeyEvent.Keypad keypad, KeyEvent.MediaKey mediaKey, KeyEvent.ModKey modKey, int functionKey, EnumSet<KeyEvent.Modifier> modifiers, String rawSequence, KeyEvent.EventType eventType, int keyCode, int shiftedKeyCode, int baseLayoutKeyCode, String associatedText) Full constructor with all Kitty Keyboard Protocol fields.
-
-
Method Details
-
getType
-
getCharacter
public char getCharacter() -
getArrow
-
getSpecial
-
getKeypad
Returns the keypad key, ornullif this is not a keypad event. -
getMediaKey
Returns the media key, ornullif this is not a media event. -
getModKey
Returns the modifier key, ornullif this is not a modifier key event. -
getFunctionKey
public int getFunctionKey() -
getModifiers
-
getRawSequence
-
hasModifier
-
getEventType
Returns the event type (press, repeat, or release). Only meaningful when the Kitty Keyboard Protocol is active with theFLAG_REPORT_EVENTSflag 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 theFLAG_REPORT_ALTERNATESflag 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 theFLAG_REPORT_ALTERNATESflag.- Returns:
- the base layout key code, or 0 if absent
-
getAssociatedText
Returns the associated text reported by the terminal. Only present when the Kitty Keyboard Protocol is active with theFLAG_REPORT_TEXTflag.- Returns:
- the associated text, or null if absent
-
toString
-