Here is some code that will play a sound when you press a key. It will only play it again if you release the key and press it again.
It uses my key monitor code which hopefully simplifies the process.
I have included to wav files for testing. Unfortunately I cannot test this fully at the moment as my work PC does not have speakers, but I will try this later when I get home.
Here is the actual code, but this is included in the zip as you also require my scancodes.dba file.
Rem Project: PlayAudio
Rem Created: 13/06/2007 08:23:01
Rem ***** Main Source File *****
backdrop on
gosub InitScanCodes
load sound "lazer 1.wav",1
load sound "lazer 2.wav",2
AddKey(Key_A,0,-1) `Key A is setup as a normal key that has to be released before pressing again
AddKey(Key_S,0,-1) `Key S is setup as a normal key that has to be released before pressing again
do
gosub KeyPress
if Keys(Key_A).KeyPressed
text 0,100,"Pressing A"
play sound 1
endif
if Keys(Key_S).KeyPressed
text 0,100,"Pressing S"
play sound 2
endif
text 0,0,"Playing Sound 1 - " + str$(sound playing(1))
text 0,15,"Playing Sound 2 - " + str$(sound playing(2))
loop
D3DFunc - Superfast Antialiased text & much much more