"""Given output from xev, determine length of keypresses."""
import sys, re

keypress_time_by_keycode = {}
event_type_re = re.compile(r'^(\S.*?) event,')
time_re = re.compile('time (\d+)')
keycode_re = re.compile('keycode (\d+)')

for line in sys.stdin:
    if event_type_re.search(line):
        event_type = event_type_re.search(line).group(1)
    if time_re.search(line):
        time = int(time_re.search(line).group(1))
    if keycode_re.search(line):
        keycode = keycode_re.search(line).group(1)
        if event_type == 'KeyPress':
            keypress_time_by_keycode[keycode] = time
        elif event_type == 'KeyRelease':
            duration = time - keypress_time_by_keycode[keycode]
            print "%s %sms" % (keycode, duration)

To unsubscribe: http://lists.canonical.org/mailman/listinfo/kragen-hacks

Reply via email to