java.lang.Object
com.googlecode.lanterna.input.KeyStroke
- Direct Known Subclasses:
KeyStroke.RealF3
,MouseAction
,ScreenInfoAction
Represents the user pressing a key on the keyboard. If the user held down ctrl and/or alt before pressing the key,
this may be recorded in this class, depending on the terminal implementation and if such information in available.
KeyStroke objects are normally constructed by a KeyDecodingProfile, which works off a character stream that likely
coming from the system's standard input. Because of this, the class can only represent what can be read and
interpreted from the input stream; for example, certain key-combinations like ctrl+i is indistinguishable from a tab
key press.
Use the keyType field to determine what kind of key was pressed. For ordinary letters, numbers and symbols, the keyType will be KeyType.Character and the actual character value of the key is in the character field. Please note that return (\n) and tab (\t) are not sorted under type KeyType.Character but KeyType.Enter and KeyType.Tab instead.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
an F3-KeyStroke that is distinguishable from a CursorLocation report. -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a KeyStroke based on a supplied keyType; character will be null and both ctrl and alt will be considered not pressed.Constructs a KeyStroke based on a supplied keyType; character will be null.Constructs a KeyStroke based on a supplied keyType; character will be null.private
KeyStroke
(KeyType keyType, Character character, boolean ctrlDown, boolean altDown, boolean shiftDown) Constructs a KeyStroke based on a supplied character, keyType is implicitly KeyType.Character.Constructs a KeyStroke based on a supplied character, keyType is implicitly KeyType.Character. -
Method Summary
Modifier and TypeMethodDescriptionboolean
static KeyStroke
fromString
(String keyStr) Creates a Key from a string representation in Vim's key notation.For keystrokes of ordinary keys (letters, digits, symbols), this method returns the actual character value of the key.long
Gets the time when the keystroke was recorded.Type of key that was pressed on the keyboard, as represented by the KeyType enum.int
hashCode()
boolean
boolean
boolean
toString()
-
Field Details
-
keyType
-
character
-
ctrlDown
private final boolean ctrlDown -
altDown
private final boolean altDown -
shiftDown
private final boolean shiftDown -
eventTime
private final long eventTime
-
-
Constructor Details
-
KeyStroke
Constructs a KeyStroke based on a supplied keyType; character will be null and both ctrl and alt will be considered not pressed. If you try to construct a KeyStroke with type KeyType.Character with this constructor, it will always throw an exception; use another overload that allows you to specify the character value instead.- Parameters:
keyType
- Type of the key pressed by this keystroke
-
KeyStroke
Constructs a KeyStroke based on a supplied keyType; character will be null. If you try to construct a KeyStroke with type KeyType.Character with this constructor, it will always throw an exception; use another overload that allows you to specify the character value instead.- Parameters:
keyType
- Type of the key pressed by this keystrokectrlDown
- Was ctrl held down when the main key was pressed?altDown
- Was alt held down when the main key was pressed?
-
KeyStroke
Constructs a KeyStroke based on a supplied keyType; character will be null. If you try to construct a KeyStroke with type KeyType.Character with this constructor, it will always throw an exception; use another overload that allows you to specify the character value instead.- Parameters:
keyType
- Type of the key pressed by this keystrokectrlDown
- Was ctrl held down when the main key was pressed?altDown
- Was alt held down when the main key was pressed?shiftDown
- Was shift held down when the main key was pressed?
-
KeyStroke
Constructs a KeyStroke based on a supplied character, keyType is implicitly KeyType.Character.A character-based KeyStroke does not support the shiftDown flag, as the shift state has already been accounted for in the character itself, depending on user's keyboard layout.
- Parameters:
character
- Character that was typed on the keyboardctrlDown
- Was ctrl held down when the main key was pressed?altDown
- Was alt held down when the main key was pressed?
-
KeyStroke
Constructs a KeyStroke based on a supplied character, keyType is implicitly KeyType.Character.A character-based KeyStroke does not support the shiftDown flag, as the shift state has already been accounted for in the character itself, depending on user's keyboard layout.
- Parameters:
character
- Character that was typed on the keyboardctrlDown
- Was ctrl held down when the main key was pressed?altDown
- Was alt held down when the main key was pressed?shiftDown
- Was shift held down when the main key was pressed?
-
KeyStroke
-
-
Method Details
-
getKeyType
Type of key that was pressed on the keyboard, as represented by the KeyType enum. If the value if KeyType.Character, you need to call getCharacter() to find out which letter, number or symbol that was actually pressed.- Returns:
- Type of key on the keyboard that was pressed
-
getCharacter
For keystrokes of ordinary keys (letters, digits, symbols), this method returns the actual character value of the key. For all other key types, it returns null.- Returns:
- Character value of the key pressed, or null if it was a special key
-
isCtrlDown
public boolean isCtrlDown()- Returns:
- Returns true if ctrl was help down while the key was typed (depending on terminal implementation)
-
isAltDown
public boolean isAltDown()- Returns:
- Returns true if alt was help down while the key was typed (depending on terminal implementation)
-
isShiftDown
public boolean isShiftDown()- Returns:
- Returns true if shift was help down while the key was typed (depending on terminal implementation)
-
getEventTime
public long getEventTime()Gets the time when the keystroke was recorded. This isn't necessarily the time the keystroke happened, but when Lanterna received the event, so it may not be accurate down to the millisecond.- Returns:
- The unix time of when the keystroke happened, in milliseconds
-
toString
-
hashCode
public int hashCode() -
equals
-
fromString
Creates a Key from a string representation in Vim's key notation.- Parameters:
keyStr
- the string representation of this key- Returns:
- the created
KeyType
-