Re: GdkEventKey --> utf-8 ?

On Thu, 10 Sep 2009, Tor Lillqvist wrote:

Because there the inserted text goes through lots of other code than
just directly mapping from key presses to characters, which is never
going to work in general.

... but is not as complicated as this text suggests. For all
those who (will) have the same problem I post a working code snippet:

  static GtkIMContext *im_context;

  static void gtk_entry_commit_cb (GtkIMContext *context, const gchar  *str, gpointer data) {
	printf("TEXT = %s\n", str); fflush(stdout);

  gboolean key_press_handler(GtkWidget *widget,  GdkEventKey *event, gpointer  data)  {
	gtk_im_context_filter_keypress(im_context, event);
	return FALSE;

  int main(int argc, char *argv[]) {
	GtkWidget *the_window;
	gtk_init (&argc, &argv);
	the_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	g_signal_connect (the_window, "key-press-event", G_CALLBACK (key_press_handler), NULL);
	im_context = gtk_im_context_simple_new ();
	g_signal_connect (im_context, "commit", G_CALLBACK (gtk_entry_commit_cb), NULL);
	return 0;


You need to read up on GtkIMContext, I think.

Indeed, and the same hint is on GdkEventKey manual page:

  "The only correct way to handle text input of text is using input
  methods (see GtkIMContext), ..."

But I think only a few programmers can convert this hint into
a working program.

J.Anders, GERMANY, TU Chemnitz, Fakultaet fuer Informatik

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