Play sound while key is pressed

I am attempting to write a simple console based piano-type program. I need the computer to play a sound when a key is pressed and stop playing the sound when a key is released. How do I do this?
Topic archived. No new replies allowed.