Re: Catching key press events
- From: zentara <zentara1 sbcglobal net>
- To: gtk-list gnome org
- Subject: Re: Catching key press events
- Date: Thu, 20 Sep 2007 14:58:41 -0400
On Wed, 19 Sep 2007 21:21:19 -0700
Arthur Barlow <arthurbarlow earthlink net> wrote:
>So, my question is simple. What is the best way for the main form to
>catch a key press event? Any snippets of code would be appreciated.
I'm a Perl guy, so excuse any c sloppiness.
/* cc -g `pkg-config --cflags --libs gtk+-2.0` -o keywatch keywatch.c */
#include <gtk/gtk.h>
#include <stdlib.h>
#include <gdk/gdkkeysyms.h>
gboolean on_key_press (GtkWidget * window,
GdkEventKey* pKey,
gpointer userdata){
if (pKey->type == GDK_KEY_PRESS){
g_print("%i\n", pKey->keyval);
switch (pKey->keyval)
{
case GDK_Escape :
gtk_main_quit ();
break;
}
}
return FALSE;
}
int
main (int argc,
char *argv[])
{
GtkWidget * window;
/* Gtk2->init; */
gtk_init (&argc, &argv);
/* my $window = new Gtk2::Window; */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (window,
"key-press-event",
G_CALLBACK (on_key_press),
NULL);
/* $window->show_all(); */
gtk_widget_show_all (window);
/* Gtk2->main; */
gtk_main ();
return 0;
}
zentara
--
I'm not really a human, but I play one on earth.
http://zentara.net/japh.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]