GtkEventControllerKey

GtkEventControllerKey — Event controller for key events

Functions

Properties

gboolean contains-focus Read
gboolean is-focus Read

Signals

void focus-in Run Last
void focus-out Run Last
void im-update Run Last
gboolean key-pressed Run Last
void key-released Run Last
gboolean modifiers Run Last

Types and Values

Object Hierarchy

    GObject
    ╰── GtkEventController
        ╰── GtkEventControllerKey

Includes

#include <gtk/gtk.h>

Description

GtkEventControllerKey is an event controller meant for situations where you need access to key events.

Functions

gtk_event_controller_key_new ()

GtkEventController *
gtk_event_controller_key_new (void);

Creates a new event controller that will handle key events.

Returns

a new GtkEventControllerKey


gtk_event_controller_key_set_im_context ()

void
gtk_event_controller_key_set_im_context
                               (GtkEventControllerKey *controller,
                                GtkIMContext *im_context);

Sets the input method context of the key controller .

Parameters

controller

a GtkEventControllerKey

 

im_context

a GtkIMContext

 

gtk_event_controller_key_get_im_context ()

GtkIMContext *
gtk_event_controller_key_get_im_context
                               (GtkEventControllerKey *controller);

Gets the input method context of the key controller .

Parameters

controller

a GtkEventControllerKey

 

Returns

the GtkIMContext.

[transfer none]


gtk_event_controller_key_forward ()

gboolean
gtk_event_controller_key_forward (GtkEventControllerKey *controller,
                                  GtkWidget *widget);

Forwards the current event of this controller to a widget .

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

Parameters

controller

a GtkEventControllerKey

 

widget

a GtkWidget

 

Returns

whether the widget handled the event


gtk_event_controller_key_get_group ()

guint
gtk_event_controller_key_get_group (GtkEventControllerKey *controller);

Gets the key group of the current event of this controller . See gdk_event_get_key_group().

Parameters

controller

a GtkEventControllerKey

 

Returns

the key group


gtk_event_controller_key_get_focus_origin ()

GtkWidget *
gtk_event_controller_key_get_focus_origin
                               (GtkEventControllerKey *controller);

Returns the widget that was holding focus before.

This function can only be used in handlers for the “focus-in” and “focus-out” signals.

Parameters

controller

a GtkEventControllerKey

 

Returns

the previous focus.

[transfer none]


gtk_event_controller_key_get_focus_target ()

GtkWidget *
gtk_event_controller_key_get_focus_target
                               (GtkEventControllerKey *controller);

Returns the widget that will be holding focus afterwards.

This function can only be used in handlers for the “focus-in” and “focus-out” signals.

Parameters

controller

a GtkEventControllerKey

 

Returns

the next focus.

[transfer none]

Types and Values

GtkEventControllerKey

typedef struct _GtkEventControllerKey GtkEventControllerKey;

Property Details

The “contains-focus” property

  “contains-focus”           gboolean

Whether focus is in a descendant of the controllers widget. See “is-focus”.

When handling focus events, this property is updated before “focus-in” or “focus-out” are emitted.

Flags: Read

Default value: FALSE


The “is-focus” property

  “is-focus”                 gboolean

Whether focus is in the controllers widget itself, as opposed to in a descendent widget. See “contains-focus”.

When handling focus events, this property is updated before “focus-in” or “focus-out” are emitted.

Flags: Read

Default value: FALSE

Signal Details

The “focus-in” signal

void
user_function (GtkEventControllerKey *controller,
               GdkCrossingMode        mode,
               GdkNotifyType          detail,
               gpointer               user_data)

This signal is emitted whenever the widget controlled by the controller or one of its descendants) is given the keyboard focus.

Parameters

controller

the object which received the signal.

 

mode

crossing mode indicating what caused this change

 

detail

detail indication where the focus is coming from

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “focus-out” signal

void
user_function (GtkEventControllerKey *controller,
               GdkCrossingMode        mode,
               GdkNotifyType          detail,
               gpointer               user_data)

This signal is emitted whenever the widget controlled by the controller (or one of its descendants) loses the keyboard focus.

Parameters

controller

the object which received the signal.

 

mode

crossing mode indicating what caused this change

 

detail

detail indication where the focus is going

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “im-update” signal

void
user_function (GtkEventControllerKey *controller,
               gpointer               user_data)

This signal is emitted whenever the input method context filters away a keypress and prevents the controller receiving it. See gtk_event_controller_key_set_im_context() and gtk_im_context_filter_keypress().

Parameters

controller

the object which received the signal.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “key-pressed” signal

gboolean
user_function (GtkEventControllerKey *controller,
               guint                  keyval,
               guint                  keycode,
               GdkModifierType        state,
               gpointer               user_data)

This signal is emitted whenever a key is pressed.

Parameters

controller

the object which received the signal.

 

keyval

the pressed key.

 

keycode

the raw code of the pressed key.

 

state

the bitmask, representing the state of modifier keys and pointer buttons. See GdkModifierType.

 

user_data

user data set when the signal handler was connected.

 

Returns

TRUE if the key press was handled, FALSE otherwise.

Flags: Run Last


The “key-released” signal

void
user_function (GtkEventControllerKey *controller,
               guint                  keyval,
               guint                  keycode,
               GdkModifierType        state,
               gpointer               user_data)

This signal is emitted whenever a key is released.

Parameters

controller

the object which received the signal.

 

keyval

the released key.

 

keycode

the raw code of the released key.

 

state

the bitmask, representing the state of modifier keys and pointer buttons. See GdkModifierType.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last


The “modifiers” signal

gboolean
user_function (GtkEventControllerKey *controller,
               GdkModifierType        keyval,
               gpointer               user_data)

This signal is emitted whenever the state of modifier keys and pointer buttons change.

Parameters

controller

the object which received the signal.

 

keyval

the released key.

 

state

the bitmask, representing the new state of modifier keys and pointer buttons. See GdkModifierType.

 

user_data

user data set when the signal handler was connected.

 

Flags: Run Last

See Also

GtkEventController