#!/usr/bin/python

# 0. Be sure gedit is NOT running.
# 1. Start two *inaccessible* terminal applications (e.g. use xterm.
#    do NOT use gnome-terminal).
# 2. In the first xterm, launch this script.
# 3. In the second xterm, launch gedit and begin typing in it.
# Expected results: All key events get consumed other than letters.
# Actual results: Locking keys (like caps lock) are also failing to
# be consumed.

import pyatspi

def listener(e):
    print e
    # Returning True means the keypress should NOT be passed through but
    # is instead consumed by our listener. We'll consume everything that
    # is not a letter to demonstrate this works.
    return not e.event_string.isalpha()

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