Skip to content

Gtk.EventControllerKey

class — extends EventController

Provides access to key events.

Constructors

new

@classmethod
def new(cls) -> EventController

Creates a new event controller that will handle key events.

Methods

forward

def forward(self, widget: Widget) -> bool

Forwards the current event of this controller to a widget.

This function can only be used in handlers for the EventControllerKey.key-pressed, EventControllerKey.key-released or EventControllerKey.modifiers signals.

Parameters:

  • widget — a GtkWidget

get_group

def get_group(self) -> int

Gets the key group of the current event of this controller.

See Gdk.KeyEvent.get_layout.

get_im_context

def get_im_context(self) -> IMContext | None

Gets the input method context of the key controller.

set_im_context

def set_im_context(self, im_context: IMContext | None = ...) -> None

Sets the input method context of the key controller.

Parameters:

  • im_context — a GtkIMContext

Signals

im-update

def on_im_update(self) -> None: ...

Emitted whenever the input method context filters away a keypress and prevents the controller receiving it.

See EventControllerKey.set_im_context and IMContext.filter_keypress.

key-pressed

def on_key_pressed(self, keyval: int, keycode: int, state: Gdk.ModifierType) -> bool: ...

Emitted whenever a key is pressed.

key-released

def on_key_released(self, keyval: int, keycode: int, state: Gdk.ModifierType) -> None: ...

Emitted whenever a key is released.

modifiers

def on_modifiers(self, state: Gdk.ModifierType) -> bool: ...

Emitted whenever the state of modifier keys and pointer buttons change.