## GtkEventControllerKey GtkEventControllerKey — Event controller for key events |

## Functions

GtkEventController * | gtk_event_controller_key_new ()
void | gtk_event_controller_key_set_im_context ()
GtkIMContext * | gtk_event_controller_key_get_im_context ()
gboolean | gtk_event_controller_key_forward ()
guint | gtk_event_controller_key_get_group ()

## Signals

void | im-update | Run Last
gboolean | key-pressed | Run Last
void | key-released | Run Last
gboolean | modifiers | Run Last

## Types and Values

| GtkEventControllerKey

## 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_key_event_get_group()`.

#### Parameters

controller | a GtkEventControllerKey |

#### Returns

the key group

## Types and Values

### GtkEventControllerKey

    typedef struct _GtkEventControllerKey GtkEventControllerKey;

## Signal Details

### 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