Skip to content

Instantly share code, notes, and snippets.

@aleroddepaz
Created June 15, 2013 19:48
Show Gist options
  • Save aleroddepaz/5789345 to your computer and use it in GitHub Desktop.
Save aleroddepaz/5789345 to your computer and use it in GitHub Desktop.
Script to keep track of keydown events during playing music.
import pygame
import time
import sys
def main(ogg_file, output_file):
pygame.display.init()
pygame.display.set_mode((100, 100))
pygame.mixer.init()
pygame.mixer.music.load(ogg_file)
f = open(output_file, 'w')
print("The music will start in one second...")
time.sleep(1)
print("The music starts now")
pygame.mixer.music.play()
start_time = time.time()
while pygame.mixer.music.get_busy():
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit(0)
if event.type == pygame.KEYDOWN:
diff = time.time()-start_time
f.write("{}\n".format(diff))
print(diff)
print("The music has just finished")
pygame.display.quit()
pygame.mixer.quit()
f.close()
if __name__ == "__main__":
if len(sys.argv) < 3:
print("Usage: {} <ogg_file> <output_file>".format(sys.argv[0]))
sys.exit(1)
main(sys.argv[1], sys.argv[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment