Skip to content

Instantly share code, notes, and snippets.

@fgolemo
Created September 30, 2017 14:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fgolemo/8e7f50e746efa4ef0e4532c724f8ec5a to your computer and use it in GitHub Desktop.
Save fgolemo/8e7f50e746efa4ef0e4532c724f8ec5a to your computer and use it in GitHub Desktop.
pygame play sample on keypress
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
import pygame
pygame.init()
pygame.mixer.init()
pygame.display.set_mode()
kick = pygame.mixer.Sound("../../Bass-Drum-1.wav")
snare = pygame.mixer.Sound("../../Ensoniq-ESQ-1-Snare.wav")
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit(); #sys.exit() if sys is imported
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_m:
kick.play()
if event.key == pygame.K_x:
snare.play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment