#!/usr/bin/python

import pyatspi

def listener(e):
    if not e.detail1:
        return

    keybinding = "No keybinding found"
    try:
        action = e.source.queryAction()
    except NotImplementedError:
        pass
    else:
        keybinding = "%s" % action.getKeyBinding(0)

    print '%s has keybinding: %s' % (e.source, keybinding)

pyatspi.Registry.registerEventListener(listener, 'object:state-changed:focused')
pyatspi.Registry.start()

