Re: [gtk-list] how to handle key presses?!?





On Sun, 13 Sep 1998, finklestein wrote:

> i am still trying to get key press events to work. ifound out why g_print
> was only printing after the program exitted, there needs to be a '\n' in
> the printed data. i suppose that flushes the output.
> 
> at any rate, i've poured over all the related example code i could find, 
> the header files and the gtk code itself. i haven't found any code yet
> that  explicitly shows the use of keypress events. would someone please
> help me out? i have also included the source file itself.
> 

You need to do three things to get keypress events.

/* 1. set event mask for widget */
 gtk_widget_set_events(GTK_WIDGET(glarea),
			GDK_EXPOSURE_MASK|
			GDK_KEY_PRESS_MASK|
			GDK_KEY_RELEASE_MASK);
 
/* 2. connect signal handlers */
  gtk_signal_connect(GTK_OBJECT(glarea), "key_press_event",
		     GTK_SIGNAL_FUNC(key_event), NULL);
  gtk_signal_connect(GTK_OBJECT(glarea), "key_release_event",
		     GTK_SIGNAL_FUNC(key_event), NULL);

/* 3. set focus to widget you want to receive keypress and/or key release 
      events */

  GTK_WIDGET_SET_FLAGS(glarea, GTK_CAN_FOCUS);
  gtk_widget_grab_focus(GTK_WIDGET(glarea));




-- 
Janne




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