If you're using VC++: int _kbhit(void); in <conio.h>. It return non-zero if a key was pressed.
Here's an example right from the docs:
Code:
/* KBHIT.C: This program loops until the user
* presses a key. If _kbhit returns nonzero, a
* keystroke is waiting in the buffer. The program
* can call _getch or _getche to get the keystroke.
*/
#include <conio.h>
#include <stdio.h>
void main( void )
{
/* Display message until key is pressed. */
while( !_kbhit() )
_cputs( "Hit me!! " );
/* Use _getch to throw key away. */
printf( "\nKey struck was '%c'\n", _getch() );
_getch();
}