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!

Tyler Jandreau
  • 4,245
  • 1
  • 22
  • 47

3 Answers3

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")
Emily
  • 2,577
  • 18
  • 38
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

Community
  • 1
  • 1
BobDoolittle
  • 1,326
  • 1
  • 12
  • 21
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.

parkydr
  • 7,596
  • 3
  • 32
  • 42
  • 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 "http://www.google.it/" – Marco Massagrande Jun 14 '13 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 '13 at 17:04