How to map a X11 KeySym to a Unicode character?

后端 未结 4 616
小蘑菇
小蘑菇 2021-01-18 12:37

This is an exact duplicate of this question; however the code linked in the accepted answer is nearly 11 years old, and this comment in the code leads to my duplicate questi

4条回答
  •  日久生厌
    2021-01-18 13:25

    This may help somebody... adapted from xmodmap source and online doc (http://tronche.com/gui/x/xlib/utilities/keyboard/XKeycodeToKeysym.html)

    KeySym ks = XKeycodeToKeysym(dpy, keycode+min_keycode, modifier);
    const char *s;
    if (ks != NoSymbol)
        s = XKeysymToString (ks);
    else {
        printf("Keycode has no symbol. Ignored.\n");
        return NULL;
    }
    
    printf ("0x%04x (%s)\n", (unsigned int)ks, s);
    printf ("wide char:%lc\n", (wchar_t)ks);
    

    Keysym is already the UTF value. The problem would be to set keycombinations... 'á' for example.

提交回复
热议问题