Re: Mouse buttons in callbacks




"Robert S. Mallozzi" <mallors@crazyhorse.msfc.nasa.gov> writes:

> Hello,
> 
> I would like to use the different mouse buttons within
> a gtk button callback to do different tasks.  How do I
> discriminate among the different mouse buttons in the
> callback function?  Currently, I have button_press_events,
> and button_release_events registered with the button, and
> this works OK, execpt I must also trap 
> enter_notify_events, and leave_notify_events to ensure that
> mouse button 1 executes its command only upon button release.
> This involves a static variable in the callback to keep 
> track of whether the cursor is on the button when it is
> released.  Surely there is a simple way to find which
> button was pressed when in a "regular" callback function?

You can do something like:

 GdkEvent *event = gtk_get_current_event();

 if (event && 
     (event->type == GTK_BUTTON_RELEASE) && 
     (event->button == 3))
   {
     /* do whatever is necessary for a right-mouse-button click */
   }

 gdk_event_free (event);

Hope this helps,
                                        Owen



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]