#!/usr/bin/python from pyxhook import HookManager from time import time import termios, sys import atexit if len(sys.argv)<2: print "usage: timelyrics audio_filename" exit() import pygame pygame.mixer.init() pygame.mixer.music.load(sys.argv[1]) pygame.mixer.music.play() for arg in sys.argv: print arg def enable_echo(fd, enabled): (iflag, oflag, cflag, lflag, ispeed, ospeed, cc) \ = termios.tcgetattr(fd) if enabled: lflag |= termios.ECHO else: lflag &= ~termios.ECHO new_attr = [iflag, oflag, cflag, lflag, ispeed, ospeed, cc] termios.tcsetattr(fd, termios.TCSANOW, new_attr) atexit.register(enable_echo, sys.stdin.fileno(), True) enable_echo( sys.stdin.fileno(),False) start=0.0 down=0.0 printeddown=0.0 state="up" def handle_up (event): global start,down,state,printeddown if printeddown!=down: print "[",down,",",time()-(start+down),"]" printeddown=down state="up" def handle_down (event): global start,down,state if state=="up": down=time()-start state="down" hm = HookManager() hm.HookKeyboard() hm.KeyUp = handle_up hm.KeyDown = handle_down start=time() print "started:",start hm.start()