How to map a X11 KeySym to a Unicode character?

半腔热情 提交于 2019-12-01 18:20:26

Try this node.js module to generate C table: https://github.com/substack/node-keysym . It is based on this dataset: https://github.com/substack/node-keysym/blob/master/data/keysyms.txt

Is there a simple function in X11/Xlib that will map a KeySym to its Unicode equivalent?

The definitive answer is no

Because Unicode was invented years after Xlib and no one ever went back to add such a thing? Most of the Xlib API is codeset independent since it was written in the days when every locale used a different character set (ISO 8859-*, Big5, JIS, etc.), so you get a char buffer appropriate to the current locale. There were a few UTF-8 specific additions in later years, but mostly we've been trying to let Xlib rest in peace since then, pushing new API design towards xcb instead.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!