I am writing an evdev-reliant daemon that needs to know the complete keyboard layout currently in use. Getting the properties of the current XKB layout is easy. You just use setxkbmap -query or setxkbmap -print. But what if I want a complete description of the currently loaded layout? A list of what each key types under what modifiers?

There's two ways to get this that I know of without relying on anything but XKB:

  1. The formal, complicated way, using setxkbmap -print to find out what symbols files are loaded from /usr/share/X11/xkb/symbols, and parsing the relevant files yourself.
  2. The quicker, dirtier, ad-hoc way, simply trying all the keys and combinations yourself, and capturing the output.

Option 1 is prone to errors and difficult to implement, and Option 2 is unwieldy. Is there a way to get a list of key combos versus character outputs? XKB has already parsed the symbols files for me, so there should really be something on the other end that outputs the result of the parsing (other than the keyboard itself).

EDIT: Ubuntu's Onboard appears to directly parse the layout file, for one. This points to there being no neat, preexisting solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.