GNOME Bugzilla – Bug 132195
EventBox not passing KEY events
Last modified: 2004-12-22 21:47:04 UTC
Set up an EventBox to grab key_press/release events, and they don't get through. The code below should print something for button & key events; it only prints button events. Possibly I've missed something. #include <gtkmm.h> #include <iostream> class ExampleWindow : public Gtk::Window { public: ExampleWindow() : m_Label("Click here to quit, quit, quit, quit, quit") { set_title ("EventBox"); set_border_width(10); add(m_EventBox); m_EventBox.add(m_Label); m_Label.set_size_request(110, 20); m_EventBox.set_events(Gdk::KEY_PRESS_MASK | Gdk::BUTTON_PRESS_MASK); m_EventBox.signal_button_press_event().connect(SigC::slot(*this, &ExampleWindow::on_eventbox_button_press) ); m_EventBox.signal_key_press_event().connect(SigC::slot(*this, &ExampleWindow::on_eventbox_key_press) ); show_all_children(); } virtual ~ExampleWindow() {} ; protected: virtual bool on_eventbox_key_press(GdkEventKey* event) { std::cout <<"KEY "<<event->keyval<<std::endl; return true; } virtual bool on_eventbox_button_press(GdkEventButton* event) { std::cout <<"BUTTON"<<std::endl; return true; } Gtk::EventBox m_EventBox; Gtk::Label m_Label; }; int main(int argc, char *argv[]) { Gtk::Main kit(argc, argv); ExampleWindow window; Gtk::Main::run(window); return 0; }
Please ask on gtk-list@gnome.org about this. Maybe somebody has some idea.
I don't know for sure but as far as I can remember keyboard events can only be received by windows which may have the focus. This is true for neither the EventBox nor the Label. You CAN receive mouse events because there is an area to click on, but there is no window which can have the focus. If this raises the question where the keyboard input is going to end: in the window. In the line: m_EventBox.signal_key_press_event().connect(SigC::slot(*this, &ExampleWindow::on_eventbox_key_press)); just remove the m_EventBox in front of it and the window will catch the events (which is always true if nobody cares for a certain event).
Please reopen if that does not solve the problem.
Right, makes sense. I had assumed that if the window had the focus, then the event boxes within it would get the key events.