How to match X11 KeySym with Unicode character?

This is an exact duplicate of this question ; however, the code associated with the accepted answer is almost 11 years old, and this comment in the code leads to my duplicate question:

The conversion of keysym → UTF-8, we hope one day will be provided by Xlib via XmbLookupString () and ideally should not be done in X Applications. But we are not there yet.

Are we still there? I know XwcLookupString , but something like ...

 wchar_t unicode = XKeySymToWideChar( keysym ); 

... will be much simpler and more logical and does not require updating when adding or changing KeySyms.

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

+5
source share
3 answers

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

Final answer no

Because Unicode was invented years after Xlib, and no one ever went back to add such a thing? Most Xlib APIs are a set of codes no matter how it was written in the days when every other set of characters (ISO 8859- *, Big5, JIS, etc.), so you get a char that matches the current language. There were several UTF-8 specific additions in subsequent years, but basically we tried Xlib calmed down since then, pushing the new xcb API design instead.

+1
source

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

+5
source

This may help someone ... adapted from xmodmap source and online document ( 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 a UTF value. The problem would be to install key combinations ... '& aacute;' eg.

0
source

Source: https://habr.com/ru/post/1392442/


All Articles