Posts

Showing posts with the label Xll

Convert ASCII Character To X11 Keycode

Answer : This question has an old, wrong answer (from @oldrinb), that oddly has never been challenged. As stated in the comment, you can't use XStringToKeysym to map chars to KeySyms in a general way. It will work for letters and numbers, but that's about it, because the KeySym name happens to map directly for those ASCII characters. For other ASCII characters such as punctuation or space it won't work. But you can do better than that. If you look at <X11/keysymdef.h> you find that for ASCII 0x20-0xFF, the characters map directly to XKeySyms . So, I'd say it's simpler to just use that range of characters directly as KeySyms , and just map the remaining 32 characters to their corresponding KeyCodes . So I'd say the code should more properly be: Display *display = ...; if ((int)c >= 0x20) { XKeysymToKeycode(display, (KeySym)c); } else { ... // Exercise left to the reader :-) } The 'else' clause will require multiple KeyCodes since f...