press key make sound

BlitzMax Forums/BlitzMax Beginners Area/press key make sound

Hi,

Can anyone help me get started with writing code for simple press a key and make a sound?

Thanks,
Tony

Strict

'
' A graphics window
Graphics 640,480

'
' Load a sound sample
Local sample:TSound = LoadSound("c:\WINDOWS\Media\chord.wav")
If sample = Null RuntimeError "Couldn't load the sound sample!"

'
' Main loop
' Exit if Esc is pressed or the close button on the window is clicked
While Not (KeyHit(KEY_ESCAPE) Or AppTerminate())

	' Clear the screen
	Cls
	
	' If space is pressed play the sound sample
	If KeyHit(KEY_SPACE)
		PlaySound(sample)
	EndIf

	' Draw something
	SetColor 255,255,255
	DrawText "Press space to play sound",0,0
	SetColor Rand(0,255),Rand(0,255),Rand(0,255)
	DrawRect Rand(600),Rand(600),20,20
	
	' Show what we have drawn
	Flip
	
Wend

' The end
End


Thanks, I appreciate that.

Tony