Re: [gtk-list] Keypress Events

On Sat, 26 Sep 1998, Brent Briggs wrote:

> I was wondering if anyone can tell me where to look for information
> about handling key presses in a GTK window. For instance, if I wanted to
> hold down the "a" key and have a function execute over and over until
> the key was released. Where do I look to find out how to do this? There
> doesn't seem to be anything about it in the tutorial. If any one can
> help, thanks in advance.

Simply bind a function to the "key_press_event" event.  You can look at
yagIRC for a specific example of this, but here is a quick example off the
top of my head.

int keyevent(GtkWidget *widget, GdkEventKey *event)
    if (event->keyval == 'a') do_stuff();
    return TRUE;

int main (int argc, char *argv[])
    GtkWidget *window;
    /* ... */
    gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
                        GTK_SIGNAL_FUNC(keyevent), NULL);
    /* ... */

Marcus Brubaker

Author, ModIC:  
CoMaintainer, yagIRC:
Owner, The 5th Dimension:
Staff Writer, Advocate:

"The first opinion that occurs to us when we are suddenly asked about
anything is not usually our own, but only the current opinion belonging to
our caste, position, or family; our own opinions seldom float on the

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