Hey,
I am basically trying to make a Piano sort of thing in C++. I know how to play a certain sound using beeps and their frequencies. But what I want is that when I press a key, the beep goes on until the key is released, which means that I want to vary the time for beep considering the time I hold the key. like It would be something like Beep(261, x) where x would be the time as long as user holds the key...
hope u guyz would be of gr8 help... :)
Sounds like you must Beep for a virtual infinite amount of time when a key is pressed. While key is still pressed, you do nothing, while beeping in correct frequency continues.
Then when user stops pressing key, you should somehow send an interupt to the sound device to stop beeping. Not sure if such a c/c++ function exists, but would asume that such a thing should be possible on the assembler level.
For a console application, you need to do some special processing.
On Windows, use SetConsoleMode() to turn off line buffering.
Then use ReadConsoleInput() in a loop (see my "is key pressed" topic, linked below, for how to create a loop waiting on input).
There are two types of codes sent by the keyboard: the "make" key code when a key is pressed, and the "break" key code when a key is released. The KEY_EVENT_RECORD's bKeyDown field tells you whether it be a press ("make") or release ("break") code.