Search code examples
x11keypress

Sending KeyPress events in X11


I have a program where for various reasons i need to send keypress events to various windows. What I am using at the moment

XEvent event;
/* set some other stuff*/
event.type = KeyPress;
event.xkey.keycode     = XKeysymToKeycode(display,XStringToKeysym(curr_key));

works for lower case letters and numbers, but I need to modify this so that it is capable of sending the enter key and upper case letters.


Solution

  • From the XStringToKeysym man page:

    void XConvertCase(KeySym keysym, KeySym *lower_return, KeySym *upper_return);

    The XConvertCase function returns the uppercase and lowercase forms of the specified Keysym, if the KeySym is subject to case conversion; otherwise, the specified KeySym is returned to both lower_return and upper_return. Support for conversion of other than Latin and Cyrillic KeySyms is implementation-dependent.

    All the keysyms are in /usr/include/X11/keysymdef.h e.g. the enter key is XK_Return. The letters are there too e.g. XK_a and XK_A.