I learned this one the hard way, so save this answer. You need to do a keyboard grab on the Gdk window (low-level window of the Gtk2 window $interface). Place this at the end of your code. Don't ask me why or how this works, it's one of those Gtk2 peculiarities, that drive people back to Tk. :-)
my $rc = Gtk2::Gdk->keyboard_grab($interface->window, 0 ,Gtk2->get_cur
+rent_event_time);
warn "keyboard grab failed ($rc)\n" unless $rc eq 'success';
print "$rc\n";
Gtk2->main;