[10255] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] Re: Key press event in drawing area

daemon@ATHENA.MIT.EDU (Brandon Long)
Wed Nov 18 17:35:58 1998

Date: Wed, 18 Nov 1998 14:31:52 -0800
From: Brandon Long <blong@fiction.net>
To: gtk-list@redhat.com
Reply-To: blong@fiction.net
Mail-Followup-To: gtk-list@redhat.com
In-Reply-To: <199811181202.NAA27501@vah.fei.tuke.sk>; from Guzma Vladimir on Wed, Nov 18, 1998 at 01:02:16PM +0100
Resent-From: gtk-list@redhat.com

On 11/18/98 Guzma Vladimir uttered the following other thing:
> Hi all
> I want to have drawing area with something write in it and I need to get key pres even for this
> Ho to get them?? 

You have to both allow the events, and set up a handler for the keypress
event, something like:

da = gtk_drawing_area_new ();
/* some code to place da */
/* Connect your callback to the signal */
gtk_signal_connect (GTK_OBJECT (da), "key_press_event", 
                    (GtkSignalFunc) keypress_callback, NULL);
/* Unmask the signal */
/* You'll probably want to or this with the other events you want,
 * typically you should grab the GDK_EXPOSURE_MASK as well for a drawing
 * area */
gtk_widget_set_events (da, GDK_KEY_PRESS_MASK | GDK_EXPOSURE_MASK);
gtk_widget_show (da);

Then, you define your callback like:
gint entry_callback (GtkWidget *w, GdkEventKey *event, gpointer data)
{
  g_print ("-I- Key Press %s\n", event->string);
}

Brandon
-- 
Brandon Long (blong@fiction.net)             [http://www.fiction.net/blong/]

  "The 'Christian Coalition' gives a bad name to both Christians and     
         coalitions." -- Her Grace the Duchess, Bonni Hall

-- 
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post