How do I create a GtkGLArea in GTK4 with key press events?

, ,

I am building a 3D level editor and trying to create a GtkGLArea with the ability to react to keyboard key presses, but cannot find anything useful in the documentation.

When searching around the web, I found the following functions:

  • g_signal_handler_connect(gtk_gesture_click_new(), “pressed”, G_CALLBACK(SceneViewOnKeyPress), 0)
  • gtk_widget_add_events(sceneView, GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK)
  • g_signal_connect(sceneView, “key_press_event”, G_CALLBACK(SceneViewOnKeyPress), 0)

Unfortunately, these functions are either unexistant in GTK4 or simply do not work.
Can someone help me?

Create a GtkEventControllerKey and add it to whatever widget you like: Gtk.EventControllerKey

It works, thank you!

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