GdkEventKey --> utf-8 ?
- From: Joerg Anders <jan informatik tu-chemnitz de>
- To: gtk-list gnome org
- Subject: GdkEventKey --> utf-8 ?
- Date: Wed, 9 Sep 2009 16:28:43 +0200 (MESZ)
Hi all!
I searched the archives but surprisingly nobody had the
question that I have:
  How can I convert GdkEventKey::keyval into UTF-8 character?
My current solution is:
       boolean key_press_handler (GtkWidget *widget,
				  GdkEventKey *event,
                                           gpointer  data)  {
        char utf8string[10];
        guint32 unichar = gdk_keyval_to_unicode(event->keyval);
        int ll = g_unichar_to_utf8(unichar, utf8string);
        utf8string[ll] = '\0';
         .....
This works on many PCs. But one user wrote me he has problems
with non-ascii characters like äöüÄÖÜ (HTML: ä ö ü
Ä Ö Ü)
He gets aouAOU instead. I inserted some printf-s in the code above and
the result is:
    event->keyval = 111
    unichar = o(0x6f)
    utf8[0] = 0x6f
That is: gdk_keyval_to_unicode() supplies a bad Unicode. But note:
The user can write those characters in an Xterm --> all works.
And he can type those characters in an GtkEntry widget.
gtk_entry_get_text(GtkEntry *entry) returns the correct UTF-8
string.(?)
I asked him to start xev and to type an ö (HTML: ö)
The result is:
KeyPress event, serial 33, synthetic NO, window 0x5e00001,
    root 0xab, subw 0x0, time 1116582, (727,296), root:(728,365),
    state 0x0, keycode 0 (keysym 0xf6, odiaeresis), same_screen YES,
    XLookupString gives 0 bytes:
    XmbLookupString gives 2 bytes: (c3 b6) "�
    XFilterEvent returns: False
KeyRelease event, serial 33, synthetic NO, window 0x5e00001,
    root 0xab, subw 0x0, time 1116685, (727,296), root:(728,365),
    state 0x0, keycode 32 (keysym 0x6f, o), same_screen YES,
    XLookupString gives 1 bytes: (6f) "o"
    XFilterEvent returns: False
I have no idea how the X11 keyboard driver converts keycode 0 
correctly (!!!) into keysym 0xf6, odiaeresis.(?)
And I cannot understand why the KeyRelease event for the same (!!!) key supplies:
   keycode 32 (keysym 0x6f, o)
He has an Ubuntu 9.04.
He tested a Debian system: The same behaviour. And in 
/etc/X11/xorg.conf is no Section "InputDevice" . (???)
Any sugestions ? Is there a better way to get the UTF-8 character ?
I know there is a GdkEventKey::string. But the manual pages says it
is deprecated and shouldn't be used any longer.
--
J.Anders, GERMANY, TU Chemnitz, Fakultaet fuer Informatik
[
Date Prev][
Date Next]   [
Thread Prev][
Thread Next]   
[
Thread Index]
[
Date Index]
[
Author Index]