Skip to content

textual.events.Key class

def __init__(self, key, character):

Bases: InputEvent

Sent when the user hits a key on the keyboard.

  • Bubbles
  • Verbose
Parameters
Parameter Default Description
key
str
required

The key that was pressed.

character
str | None
required

A printable character or None if it is not printable.

aliases instance-attribute

aliases: list[str] = _get_key_aliases(key)

The aliases for the key, including the key itself.

character instance-attribute

character = (
    key
    if len(key) == 1
    else None if character is None else character
)

A printable character or None if it is not printable.

is_printable property

is_printable: bool

Check if the key is printable (produces a unicode character).

Returns
Type Description
bool

True if the key is printable.

key instance-attribute

key = key

The key that was pressed.

name property

name: str

Name of a key suitable for use as a Python identifier.

name_aliases property

name_aliases: list[str]

The corresponding name for every alias in aliases list.