If your compiler has conio.h as a header, then you're in luck, as this program shows:
Code:
/*
kbhit Checks for currently-available keystrokes.
Syntax:
int kbhit(void);
Prototype in:
conio.h
Remarks:
kbhit checks to see if a keystroke is currently available.
Any available keystrokes can be retrieved with getch or getche.
Return Value:
If a keystroke is available, kbhit returns a nonzero integer; if not, it
returns 0.
Portability:
kbhit works in DOS and Windows
See Also:
getch getche
Example:
*/
#include <conio.h>
#include <stdio.h>
int main(void)
{
int key1;
cprintf("Press any key to continue:");
while (!kbhit()) /* do nothing */ ;
//getchar() (below) is standard C. getch() is part of the
//non-standard (but useful), conio.h
key1 = getch(); //get a letter, w/o an enter key being needed
//print the int that was pressed, as a letter
printf("\r\nA key was pressed: %c", key1);
//print the same int as it's ascii int value
printf("\r\nA key was pressed: %d", key1);
printf("\n\t\t\t Press Enter When Ready ");
key1 = getchar(); //pause the screen from closing
return 0;
}
If you don't have conio.h, then check out the cboard tutorial on it. There's a game in the thread at first, but keep going down the replies and you'll come to the virtual keys function that MS has set up for Windows.