1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#!/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()
|