Computer Science Canada

playing sound when any button is pressed

Author:  junkpro11 [ Sun May 09, 2004 10:34 am ]
Post subject:  playing sound when any button is pressed

how do u play a sound whenever anything on the keyboard is pressed?

Author:  Paul [ Sun May 09, 2004 11:18 am ]
Post subject: 

This works Razz
code:

setscreen ("nocursor")
var key : string (1)
loop
getch (key)
Music.Play ("a")
end loop

Author:  Mazer [ Sun May 09, 2004 11:43 am ]
Post subject: 

Shocked
How about this instead?
code:

setscreen ("nocursor")
var key : string (1)
loop
    if hasch then
        getch (key)
        Music.Play ("a")
    end if
end loop

Author:  junkpro11 [ Sun May 09, 2004 2:58 pm ]
Post subject: 

can u explain how the code works?

it would help alot

Author:  Dan [ Sun May 09, 2004 3:40 pm ]
Post subject: 

code:

setscreen ("nocursor")

var key : string (1) %a char to store the keyinput

%main loop that keeps the progame runing
loop
   
    if hasch then %if a key has been hit on the key borad

        getch (key) %input the key in to the char var

        Music.Play ("a") %plays the note A like on a paino

    end if

end loop

Author:  s_climax [ Sun May 09, 2004 4:37 pm ]
Post subject: 

It works better to do this.

code:

var key : string (1)
loop
getch (key)
Music.Play ("16a")
end loop

Author:  Mazer [ Sun May 09, 2004 5:38 pm ]
Post subject: 

But that halts the program waiting for the user to give input, that's why I had the if statement with hasch.

Author:  recneps [ Sun May 09, 2004 6:42 pm ]
Post subject: 

whgen i run that and hit the key before it stop, my comp bluscreens, wtf? :/

Author:  Dan [ Sun May 09, 2004 11:13 pm ]
Post subject: 

both verson work fine for me, dose your comp have a sound card?


: