Re: GtkText Widget

On Sun, 2001-09-09 at 14:18, Farhan Chaudhary wrote:
> Hi,
> I am new to Gtk & I have a problem. Plz help me.
> Is there anyway I can execute a callback when cursor keys are pressed in the GtkText widget.

To capture any key event you add a signal handler to "key_press_event".
Then you just look at the key-value in the event structure. I've
attached a small example of capturing both key-events and mouse-events.


Keep Smiling Everyone Loves A Moron
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>

static void
key_event (GtkWidget * dummy, GdkEvent * event)
  g_print ("key_event\n");

static void
button_event (GtkWidget * dummy, GdkEvent * event)
  g_print ("button_event\n");

main (int argc, char *argv[])
  GtkWidget *win;
  GtkWidget *text;

  gtk_init (&argc, &argv);

  win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  text = gtk_text_new (NULL, NULL);
  gtk_text_set_editable (GTK_TEXT (text), TRUE);
  gtk_container_add (GTK_CONTAINER (win), text);

  /* setting up signals */
  gtk_signal_connect (GTK_OBJECT (text), "key_press_event",
		      GTK_SIGNAL_FUNC (key_event), NULL);
  gtk_signal_connect (GTK_OBJECT (text), "button_press_event",
		      GTK_SIGNAL_FUNC (button_event), NULL);

  gtk_widget_show_all (win);

  gtk_main ();

  return 0;

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