- java.lang.Object
-
- org.jline.terminal.KeyEvent
-
public class KeyEvent extends java.lang.ObjectRepresents 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 Classes Modifier and Type Class Description static classKeyEvent.ArrowDefines arrow key directions.static classKeyEvent.EventTypeDefines the type of key action for protocols that distinguish press, repeat, and release events (e.g., Kitty Keyboard Protocol).static classKeyEvent.KeypadDefines keypad keys reported by the Kitty Keyboard Protocol.static classKeyEvent.MediaKeyDefines media keys reported by the Kitty Keyboard Protocol.static classKeyEvent.ModifierDefines modifier keys that can be held during a key event.static classKeyEvent.ModKeyIdentifies individual modifier keys for standalone key events.static classKeyEvent.SpecialDefines special keys.static classKeyEvent.TypeDefines the types of key events that can occur.
-
Constructor Summary
Constructors Constructor Description KeyEvent(char character, java.util.EnumSet<KeyEvent.Modifier> modifiers, java.lang.String rawSequence)Creates a character key event.KeyEvent(int functionKey, java.util.EnumSet<KeyEvent.Modifier> modifiers, java.lang.String rawSequence)Creates a function key event.KeyEvent(java.lang.String rawSequence)Creates an unknown key event.KeyEvent(KeyEvent.Arrow arrow, java.util.EnumSet<KeyEvent.Modifier> modifiers, java.lang.String rawSequence)Creates an arrow key event.KeyEvent(KeyEvent.Special special, java.util.EnumSet<KeyEvent.Modifier> modifiers, java.lang.String rawSequence)Creates a special key event.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.KeyEvent(KeyEvent.Type type, char character, KeyEvent.Arrow arrow, KeyEvent.Special special, KeyEvent.Keypad keypad, KeyEvent.MediaKey mediaKey, KeyEvent.ModKey modKey, 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)Full constructor with all Kitty Keyboard Protocol fields.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyEvent.ArrowgetArrow()java.lang.StringgetAssociatedText()Returns the associated text reported by the terminal.intgetBaseLayoutKeyCode()Returns the base layout key code (the key on a US keyboard layout).chargetCharacter()KeyEvent.EventTypegetEventType()Returns the event type (press, repeat, or release).intgetFunctionKey()intgetKeyCode()Returns the Unicode key code as reported by the Kitty Keyboard Protocol.KeyEvent.KeypadgetKeypad()Returns the keypad key, ornullif this is not a keypad event.KeyEvent.MediaKeygetMediaKey()Returns the media key, ornullif this is not a media event.java.util.EnumSet<KeyEvent.Modifier>getModifiers()KeyEvent.ModKeygetModKey()Returns the modifier key, ornullif this is not a modifier key event.java.lang.StringgetRawSequence()intgetShiftedKeyCode()Returns the shifted variant key code.KeyEvent.SpecialgetSpecial()KeyEvent.TypegetType()booleanhasModifier(KeyEvent.Modifier modifier)java.lang.StringtoString()
-
-
-
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.
-
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, java.util.EnumSet<KeyEvent.Modifier> modifiers, java.lang.String rawSequence, KeyEvent.EventType eventType, int keyCode, int shiftedKeyCode, int baseLayoutKeyCode, java.lang.String associatedText)
Full constructor with all Kitty Keyboard Protocol fields.
-
-
Method Detail
-
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, ornullif this is not a keypad event.
-
getMediaKey
public KeyEvent.MediaKey getMediaKey()
Returns the media key, ornullif this is not a media event.
-
getModKey
public KeyEvent.ModKey getModKey()
Returns the modifier key, ornullif this is not a modifier key event.
-
getFunctionKey
public int getFunctionKey()
-
getModifiers
public java.util.EnumSet<KeyEvent.Modifier> getModifiers()
-
getRawSequence
public java.lang.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 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
public java.lang.String 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-