這個,我是去 Google Code Search 找來的,雖然 devhelp 可以查指令,但沒有範例,還是很難猜到怎麼用。
#include <gdk/gdkkeysyms.h> // 定義按鍵值的 header
static gboolean press_event( GtkWidget* widget, GdkEventButton* event, gpointer data )
{
if( debug )
g_print("press_event: x=%f y=%f button=%d\n", event->x, event->y, event->button );
if( event->button==1 ) { // left
}
}
static gboolean key_event( GtkWidget* widget, GdkEventKey* event )
{
if( debug )
g_print( "event->keyval=%d event->state=%d\n", event->keyval, event->state );
switch (event->keyval) {
// 省略...
}
return TRUE;
}
int main( int argc, char* argv[] )
{
// 省略一萬行...
g_signal_connect( drawing_area, "button_press_event", G_CALLBACK( press_event ), NULL );
g_signal_connect( drawing_area, "key_press_event", G_CALLBACK( key_event ), NULL );
// 要接收 button_press_event 跟 key_press_event 喔~
gtk_widget_set_events( drawing_area, gtk_widget_get_events(drawing_area) | GDK_BUTTON_PRESS_MASK | GDK_KEY_PRESS_MASK );
// 省略兩萬行...
}
沒有留言:
張貼留言