import pyatspi from collections import defaultdict count = defaultdict(int) def callback(event): global count if event is None: return if type(event) == pyatspi.event.DeviceEvent: return if event.host_application is None: return if event.host_application.name == "Minefield" or event.host_application.name == "Firefox" or event.host_application.name == "Thunderbird": #if event.type == "object:state-changed:focused": print event count[event.type] += 1 try: reg = pyatspi.Registry events = pyatspi.EVENT_TREE.keys() events = list(set([event.strip(':') for event in events])) reg.registerEventListener(callback, *events) reg.start() except KeyboardInterrupt: for k in count.keys(): print ("%s:%d") % (k,count[k]) print "bye"