views:

159

answers:

1

I have a device that outputs a limited number of keycodes (for example a keyboard-wedge barcode scanner) and I want to know what those keycodes will type on all possible keyboard layouts. I'd like to write an X11 client that sets the keyboard layout to each installed keymap and then records the Unicode received for each keypress from the device.

How do I get the list of all installed keyboard layouts?

+1  A: 

x.org stores its keyboard layouts in XML now. It's easy to parse the available layouts from /usr/share/X11/xkb/rules/base.xml. Ubuntu has a similar evdev.xml in that directory, I'm not sure how they differ. In Python:

#!/usr/bin/env python
# Enumerate available xkb layouts
import lxml.etree
repository = "/usr/share/X11/xkb/rules/base.xml"
tree = lxml.etree.parse(file(repository))
layouts = tree.xpath("//layout")
for layout in layouts:
    layoutName = layout.xpath("./configItem/name")[0].text
    print layoutName
    for variant in layout.xpath("./variantList/variant/configItem/name"):
        variantName = variant.text
        print layoutName, variantName
joeforker