GTK 4: GtkEventControllerKey problem

I have successfully added to a GtkDrawingArea:

  • a GtkGestureClick,
  • a GtkEventControllerScroll,
  • a GtkEventControllerMotion.

But my GtkEventControllerKey does not emit any key-pressed signal.

My Fortran code looks like this:

  controller_k = gtk_event_controller_key_new()
  call g_signal_connect(controller_k, "key-pressed"//c_null_char, &
           & key_press_callback_function)
  call gtk_widget_add_controller(my_drawing_area, controller_k)

The same kind of code was successfully used for the other controller types. Have I missed some subtle thing concerning GtkEventControllerKey ?

Is it related to this GTK 3 issue: Using Gtk.EventControllerKey ?

Yes, you widget needs to have input focus to receive key events. See e.g. the docs for gtk_widget_set_focusable().

Thank you @baedert !

That line fixed the problem:

call gtk_widget_set_focusable(my_drawing_area, TRUE)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.