The keyboard interfaces and protocols in X

Sam Varshavchik sam.varshavchik at
Mon Feb 14 13:01:01 UTC 2022

I should preface by saying that I reverse-engineered this, based on
time-consuming searches, and by picking up some clues in xorg's
source. This was a long time ago, I don't remember where I found
everything, I forgot, and only have the end results. This is what I

You need the keycode and the current input mask. keysym_lookup()
produces both a unicode character and a keysym.

Note that this deals with keyboard events only. Other kinds of X
interactions will introduce you to wonderful compound_text encoding.
That's going to be its own slice of heaven.

On Mon, Feb 14, 2022 at 4:58 AM Andrew Bainbridge <andy at> wrote:
> I tried to do something similar and had the same experience. I still don't know how to convert keyboard events to something useful like UTF-8. (I was actually aiming for Latin-1 to start with).
> My terrible code is here:
> The keycode conversions are done in x11KeycodeToDfKeycode() and dfKeycodeToAscii().
> If someone would like to tell me (and John) how to do better, that'd be great, as long as it doesn't involve adding any dependencies to my code :-)
> - Andy
> On Sun, Feb 13, 2022, at 5:01 PM, John Found wrote:
> Hi.
> I am trying to create a X client that to communicate to X server by the
> raw protocol, not using any libraries, such as XLib or XCB.
> While with the graphics part it was simple and straightforward task,
> solved by simply following the protocol (The documentation on X11 is
> pretty complete and well written) and extensions documentation is
> available (although the MIT-SHM documentation on the protocol does not
> exists at all), I have stuck with the keyboard part of
> the protocol.
> The biggest problem is the conversion from the keycodes into the
> Unicode characters (of course where it is possible).
> Do I need XKEYBOARD extension? On only XINPUT. Or both. The
> documentation is complex and poorly written. I have a feeling that part
> of it was written not to be useful, but simply because it had to be
> written.
> So, the question:
> What is the simplest, canonical, expected way to handle the keyboard
> events in X protocol in order to obtain the Unicode codes of the
> pressed keys? In raw protocol therms. And supporting multiple
> languages, of course.
> I understand that some processing on the client side is required, but I
> am missing the whole picture of the process.
> Best Regards.
> John Found

More information about the xorg mailing list