Skip to content

Gdk.KeyEvent

class — extends Event

An event related to a key-based device.

Methods

get_consumed_modifiers

def get_consumed_modifiers(self) -> ModifierType

Extracts the consumed modifiers from a key event.

get_keycode

def get_keycode(self) -> int

Extracts the keycode from a key event.

get_keyval

def get_keyval(self) -> int

Extracts the keyval from a key event.

get_layout

def get_layout(self) -> int

Extracts the layout from a key event.

get_level

def get_level(self) -> int

Extracts the shift level from a key event.

get_match

def get_match(self) -> tuple[bool, int, ModifierType | int]

Gets a keyval and modifier combination that will match the event.

See KeyEvent.matches.

is_modifier

def is_modifier(self) -> bool

Extracts whether the key event is for a modifier key.

matches

def matches(self, keyval: int, modifiers: ModifierType | int) -> KeyMatch

Matches a key event against a keyval and modifiers.

This is typically used to trigger keyboard shortcuts such as Ctrl-C.

Partial matches are possible where the combination matches if the currently active group is ignored.

Note that we ignore Caps Lock for matching.

Parameters:

  • keyval — the keyval to match
  • modifiers — the modifiers to match