GNOME Bugzilla – Bug 419923
No key press events signals for some keys
Last modified: 2007-04-15 12:06:43 UTC
For some keys gtkmm does not generate key press event signals. At least arrow keys, tab, and enter signals are lost. For example ctrl, alt, capslock, and esc generate signals. Here's some code that i'm using to test this. It creates a window with no children, and andother class which has the signal handler. main: Gtk::Window win; win.set_title("DrawingArea"); MyArea area; win.add_events(Gdk::KEY_PRESS_MASK); win.signal_key_press_event().connect(sigc::mem_fun(area, &MyArea::key_press_event)); signal handler: bool MyArea::key_press_event(GdkEventKey* event) { std::cout << "Pressed " << event->keyval << "\n"; return true; } In plain gtk arrow key signals are generated. See: http://www.gtkforums.com/viewtopic.php?t=187&view=previous&sid=a7c9ab2507ce106b147fde43fe3b7e6d
Created attachment 84898 [details] test case I've quickly made a simple test case. It seems that really the key_press signal is not emmitted for some reason for the arrow keys, space, enter... (hope to catch time to investigate later), while key_released is ok.
Could we have an equivalent GTK+ test case please?
Hey. This is intruiging. How about a C test case?
Created attachment 85906 [details] C test case
The problem here is that g_signal_connect connects before the default signal handler runs and gtkmm signals connect after (by default). Using g_signal_connect_after in the C testcase yields the same result as the C++ version, and using win.signal_key_press_event().connect(sigc::ptr_fun(...), false) in the C++ testcase results in the same behaviour as in the C version. Probably, the default signal handler of the key press event returns TRUE for some keys and therefore prevents other handlers from being run. However, this is not a gtkmm issue. Perhaps a GTK+ one, but I think it is OK the way it is.
Ah, sorry. I didn't notice that it was this simple. This is a fairly well-known behaviour and the solution is mentioned already in the documentation: http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/apbs06.html I still believe that connect-after is a far better default. I'd rather have these problems than the other problems. It's unpleasant, but it's not something that we can really change. The closest thing to an open bug about it is this: http://bugzilla.gnome.org/show_bug.cgi?id=126213 See also: http://bugzilla.gnome.org/show_bug.cgi?id=89780 http://bugzilla.gnome.org/show_bug.cgi?id=125969