#!/usr/bin/python
import pyatspi

def listener(e):
    obj = e.source

    app = obj.getApplication()
    if app.name != "gnome-shell":
        return

    print e

def onKeyPressOrRelease(event):
    print "onKeyPressOrRelease: %s" % event

pyatspi.Registry.registerEventListener(
    listener,
    "object:state-changed:selected",
    "object:state-changed:showing")

pyatspi.Registry.start()

pyatspi.Registry.registerKeystrokeListener(
    onKeyPressOrRelease,
    kind=(pyatspi.KEY_PRESSED_EVENT, pyatspi.KEY_RELEASED_EVENT))

pyatspi.Registry.start()

pyatspi.Registry.deregisterKeystrokeListener(
    onKeyPressOrRelease,
    kind=(pyatspi.KEY_PRESSED_EVENT, pyatspi.KEY_RELEASED_EVENT))

pyatspi.Registry.stop()
