Thanks,
I did an add_events(Gdk::BUTTON_PRESS_MASK); and it worked properly. Aaron Geier -----Original Message----- From: Jonathon Jongsma [mailto:[EMAIL PROTECTED] Sent: Thursday, August 23, 2007 3:46 PM To: Aaron Geier Cc: [email protected] Subject: Re: Mouse Events and Gtkmm/Gdk On 8/23/07, Aaron Geier <[EMAIL PROTECTED]> wrote: > > Hello, > > I'm slightly confused as to how mouse events work with gdk, gtk, and gtkmm. > > I just wanted to test out some basic functions to test out mouse handling > and keyboard handling. > > > > The following is my main window class that I use to start Gtkmm. There is > nothing fancy, and there is really no interaction. Basically I just want to > press keys and mouse buttons and have information printed to stdout. > > Class MyWindow : public Gtk::Window > > { > > > > Public: > > MyWindow(); > > virtual ~MyWindow(); > > > > virtual bool on_key_release_event(GdkEventKey *event) > { > > cerr << event->keyval << endl; > > return true; > > } > > > > virtual bool on_button_event(GdkEventButton *event) > > { > > cerr << event->type << endl; > > return true; > > } > > > > }; > > > > When I instantiate this class as my main gtk window and run the program, it > prints out all the keyboard strokes that I touch. However, when I do any > mouse button pressing, nothing is printed out to the screen. Am I using the > wrong event type for mouse presses, or must I do something special to log > mouse presses? Assuming that you actually mean on_button_press_event() instead of on_button_event(), that should be the correct event (unless you were trying to catch button releases, which would be on_button_release_event()). But this is another one of those things that's not obvious to newcomers: not all widgets are configured to generate all events by default. For some widgets (e.g. a Gtk::Button) whose purpose is to be clicked, the button press event will obviously be enabled by default. But for other widgets that are unlikely to need to handle button press events (e.g. DrawingArea), these events are disabled by default as a performance optimization. If you /do/ need to handle these events, you need to explicitly enable them with either add_events() [1] or set_events() [2]. Unfortunately, I don't think that there is even any documentation on what the default event masks are for all of the different widgets (if somebody knows of such a thing, please let me know). The other thing to keep in mind is that there are also some widgets which can't actually receive *any* events. See [3] for more information. Hope that helps. [1] http://gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.h tml#1af589cb1d8764be5abf5579ffb69bec [2] http://gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1Widget.h tml#deb38a3d5988a0e31055bbd2edb2e954 [3] http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch13.html -- jonner _______________________________________________ gtkmm-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/gtkmm-list
