#!/usr/bin/python

import pyatspi
from gi.repository import Gdk

def onKey(e):
    typeString = '(unknown)'
    if e.type == pyatspi.KEY_PRESSED_EVENT:
        typeString = '>>> KEY PRESSED '
    elif e.type == pyatspi.KEY_RELEASED_EVENT:
        typeString = '<<< KEY RELEASED'

    eventString = e.event_string or Gdk.keyval_name(e.id)
    print '%s: %s' % (typeString, eventString)

pyatspi.Registry.registerKeystrokeListener(
    onKey, mask=range(256), kind=(pyatspi.KEY_PRESSED_EVENT, pyatspi.KEY_RELEASED_EVENT))
pyatspi.Registry.start()
