Hi everyone, basically i'm writing a simple program in c++ to trigger a beep from the internal speaker much like a musical keyboard except i'm having trouble with capturing key press
how would i be able to trap a key press then initiate a beep, i have tried using kbhit() in a If statement but not able to detect the keyboard press, as i dont know the keyboard button matrix addresses here is my code, tell me what you think
/*Author:Joseph Ioannou
Description: Simple program which detects input from keyboard and makes sounds :) */
#include <stdio.h>
#include <conio.h>
#include <windows.h> // WinApi header file
//Sleep(500); // 500 ms delay
//Beep(523,500); // 523 hertz (C5) for 500 milliseconds
int keychk[9] = {1, 2, 3, 4, 5, 6, 7, 8, 9}; // simple key check int array
int main()
{
puts("");
// 523 hertz (C5) for 500 milliseconds
Beep(500,1000);
Beep(500,1000);
Beep(500,1000);
Beep(400,800);
Beep(500,500);
Beep(600,500);
Beep(400,800);
Beep(500,500);
Beep(600,500);
puts("Waiting for key press to begin");
getchar(); // key wait
printf("Please press a key");
if(kbhit()!='a')
{
printf("a key is pressed");
}
else return 0;
}
the program starts by a simple text statement then plays a small tune like the first nine notes from star wars as an introduction
the keychk is just an array i was going to use to compare the key press to the number pad as i thought it would be useful
the kbhit if statement is just an example i left in to show you what i ment, hope this helps you help me (the printf will be replaced with a beep)
thanks in advance, Joe