Rust GTK4 - Key Pressed
I'm currently building an application using gtk-rs using GTK4. To react to key presses the EventControllerKey can be used. This is added as a controller to the main window.
let control_key = gtk::EventControllerKey::new();
control_key.connect_key_pressed(move |_, key, _, _| {
match key {
gdk::Key::Right => { ... },
gdk::Key::Left => { ... },
gdk::Key::Up => { ... },
gdk::Key::Down => { ... },
_ => (),
}
glib::Propagation::Proceed
});
window.add_controller(control_key);