#!/usr/bin/env python import os import struct import sys SIZEOF_INPUT_EVENT = struct.calcsize('llHHi') # time (2 * long), type, code, value quiet = False def main_loop(fd): while True: s = os.read(fd, SIZEOF_INPUT_EVENT) if len(s) != SIZEOF_INPUT_EVENT: print >>sys.stderr, "Read %d bytes, expected %d" % \ (len(s), SIZEOF_INPUT_EVENT) break [tsec, tusec, type, code, value] = struct.unpack('llHHi', s) if not quiet or type: print "T:%10.2f t:%02x c:%02x v:%02x" % \ (tsec + float(tusec) / 1000000, type, code, value) def main(): if sys.argv[1] == '-q': global quiet quiet = True filename = sys.argv[2] else: filename = sys.argv[1] fd = os.open(filename, os.O_RDONLY) main_loop(fd) if __name__ == '__main__': main()