Skip to content

Key

The Key event is sent to a widget when the user presses a key on the keyboard.

  • Bubbles
  • Verbose

Attributes

attribute type purpose
key str Name of the key that was pressed.
char str or None The character that was pressed, or None it isn't printable.

Code

Bases: InputEvent

Sent when the user hits a key on the keyboard.

Parameters:

Name Type Description Default
sender MessageTarget

The sender of the event (the App).

required
key str

A key name (textual.keys.Keys).

required
char str | None

A printable character or None if it is not printable.

required

Attributes:

Name Type Description
key_aliases list[str]

The aliases for the key, including the key itself

is_printable() property

Return True if the key is printable. Currently, we assume any key event that isn't defined in key bindings is printable.

Returns:

Name Type Description
bool bool

True if the key is printable.

key_name() property

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