2014-05-07 163 views

回答

6

一個簡單的方法來監聽任何鼠標點擊,無論是向左或向右會是這樣:

g_signal_connect(
    G_OBJECT(button) 
    "button-press-event", 
    G_CALLBACK(btn_press_callback), 
    NULL 
); 

然後,回調函數:

gboolean btn_press_callback(GtkWidget *btn, GdkEventButton *event, gpointer userdata) 
{ 
    if (event->type == GDK_BUTTON_PRESS && event->button == 3) 
    {//3 is right mouse btn 
     //do stuff 
     return true;//or false 
    } 
    if (event->type == GDK_BUTTON_PRESS && event->button == 1) 
    {//1 is left mouse btn 
    } 
} 

等。 .. More info here

一些例子,使用GTK + -2但仍然有用,can be found here

相關問題