Skip to content

Message

KeyEvent

Bases: AttrEnum

Keyboard event message type enumerator to use as KeyMsg type attribute.

PRESS = 'PRESS'

RELEASE = 'RELEASE'

TAP = 'TAP'

Key press and release. Isn't assigned by KeyIn but can be sent with KeyOut.

KeyMsg

KeyMsg(
    type: KeyEvent,
    shortcut_or_keycodes: str | Iterable[pynput.keyboard.Key],
    *,
    source: None | KeyIn = None
)

Bases: Msg

Keyboard event message

Parameters:

  • type (KeyEvent) –

    Keyboard event type

  • shortcut_or_keycodes (str | Iterable[Key]) –

    keyboard shortcut description or event key codes

  • source (None | KeyIn, default: None ) –

    The KeyIn instance that generated the message

Tip

Run GUI and enable keyboard input. Use log to get messages with shortcuts you need.

ctime

ctime: float

Message creation time in "Unix time" format

type

type: KeyEvent

Keyboard event type

keycodes

keycodes: list[Key]

Keycodes in the order they were pressed. Use when press order matters.

source

source: None | KeyIn

Input port instance that generated the message

shortcut

shortcut: str

Keyboard shortcut description like 'ctrl+shift+t'. Stays the same for any key press order.

matches

matches(
    type: None | Container[KeyEvent] | KeyEvent = None,
    shortcut: None | Container[str] | str = None,
) -> bool

Checks if message's attributes match all provided attribute conditions:

  1. If condition is None or omitted, it matches anything.

  2. If condition equals attribute, it matches the attribute.

  3. If condition is a container and contains the attribute, it matches the attribute.

Use Not(condition) to invert condition matching.

Returns:

  • bool

    True if all attributes match, False if any does not match