Send String to Window input field

Glynn Clements glynn at
Fri Feb 19 09:42:59 PST 2010

ac at wrote:

> I try to send a string to an input field of an application. I think the
> only way is to use the XSendEvent function and send the keycode of every
> single character of my string. But how could I get the special keys like
> shift or alt for characters like '%'?

XKeysymToKeycode() converts KeySyms to keycodes. You can find the
keysyms in <X11/keysymdef.h>, e.g. XK_percent for '%'. Or you can look
at the output from "xmodmap -pk", and add the XK_ prefix. Or you can
enumerate the keyboard mapping yourself with XGetKeyboardMapping() and
call XKeysymToString() on each KeySym.

You probably don't need to explicitly send Alt/Shift/etc events;
simply setting the state field in the XKeyEvent structure should

Glynn Clements <glynn at>

More information about the xorg mailing list