0

My need is to convert a char into a keycode to send an event with XSendEvent.

I'm using XStringToKeysym("a"), but when I use chars like : I get an invalid result.

Is it possible to bypass use of keysym and convert char directly to XKeyEvent keycode?

Any help appreciated!

1

3 Answers 3

3

You can get the Unicode representation of the character and prepend U to it. For instance, in case of : these would do the same thing:

XStringToKeysym("colon")
XStringToKeysym("U003A")
1

Actually, you can do better than @Artyom's answer. 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 KeyCodes, and just map the remaining 32 characters.

For a more detailed answer including example code, see: https://stackoverflow.com/a/25771958/3149905

0

XStringToKeysym converts a name to a keysym, so ":" won't work, you have to use "colon" instead.

Keycodes are not standard (keyboard layouts vary), hence keysyms are used and are defined in <X11/keysymdef.h>.

The best you can do, is to use XKeysymToKeycode with XK_a and XK_colon.

2
  • Thank you for your reply, but my problem is that I don't know which char I have to convert. Infact I have to send a complete string, like "google.it" Jun 14, 2013 at 15:16
  • I think you'll have to make a look up table, character to key sym, maybe do a-z with XStringToKeysym but lookup the punctuation
    – parkydr
    Jun 14, 2013 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.