Re: [gtk-list] getting netry key-presses
- From: Brandon Long <blong fiction net>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] getting netry key-presses
- Date: Wed, 23 Sep 1998 13:48:23 -0700
On 09/23/98 Robin Ericsson uttered the following other thing:
> I know there was a thread about this about a month ago but never got to
> really understand that.
>
> What I want is to get the keys "up" and "down". Should I then use connect to
> key_press_event and wait for right widget and keys? And who do I check for
> those keys?
Basically, you have to grab key_press_event:
static GList *EntryHistory = NULL;
gtk_signal_connect (GTK_OBJECT (entry), "key_press_event",
(GtkSignalFunc) entry_key_press, NULL);
Then, you can handle it like:
int visual_entry_key_press (GtkEntry * entry, GdkEventKey * event, void *data)
{
GList *li;
if (event->state & GDK_CONTROL_MASK)
{
switch (event->keyval)
{
case 'C':
case 'c':
if (event->state & GDK_CONTROL_MASK)
{
send_break ();
return TRUE;
}
break;
}
}
else
{
switch (event->keyval)
{
case GDK_Up:
case GDK_KP_Up:
li = visual_entry_find
(gtk_entry_get_text (GTK_ENTRY (entry)));
if (li)
li = li->prev;
if (li)
gtk_entry_set_text (GTK_ENTRY(entry), (gchar *) li->data);
gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
return TRUE;
break;
case GDK_Down:
case GDK_KP_Down:
li = visual_entry_find (gtk_entry_get_text (GTK_ENTRY (entry)));
if (li)
li = li->next;
if (li)
gtk_entry_set_text (GTK_ENTRY(entry), (gchar *) li->data);
gtk_signal_emit_stop_by_name (GTK_OBJECT (entry), "key_press_event");
return TRUE;
break;
}
}
return FALSE;
}
GList * visual_entry_find (gchar *text)
{
GList *list;
list = EntryHistory;
while (list && list->data)
{
if (!strcmp ((char *)list->data, text))
return list;
list = list->next;
}
return NULL;
}
Basically, if your handler finishes handling of the keypress event, then
you emit the stop signal and return true, else return false.
Brandon
--
Brandon Long "For some reason, the act of talking to Absolute
MD6 Crash Test Dummy Evil makes chocolate syrup drip from your pineal
blong@fiction.net Gland." -- LeTeXan, "Today's Suck" 6/3/97
I'm too low on the totem pole to speak for Intel.
http://www.fiction.net/blong/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]