hi...
normal scanf(), gets(), getc() only wait for user to enter input and end when user press "Enter"...,
but I wanted to know is there a function that active only if there is a keystroke from the keyboard........
Printable View
hi...
normal scanf(), gets(), getc() only wait for user to enter input and end when user press "Enter"...,
but I wanted to know is there a function that active only if there is a keystroke from the keyboard........
Try using
GetAsyncKeyState(int Keycode);
For example:
Code:#include <windows.h>
#include <stdio.h>
int main(void){
bool WaitingForKey=true;
while(WaitingForKey){
if(GetAsyncKeyState(VK_SPACE)){
MessageBox(0,"You pressed SPACE!", "Hey",MB_OK);
WaitingForKey=false;
}
}
getchar(); //Pause.
return 0;
}
Well... most windows compliers supply function getch to do this, though getch is not standard function.
Code:#include <conio.h> /* not a standard header file */
int main( void )
{
getch();
return 0;
}
try kbhit() .
The OP never stated the platform.
Please see http://faq.cprogramming.com/cgi-bin/...&id=1043284385 and the first question on http://www.eskimo.com/~scs/C-faq/s19.html.
Preferably, read every FAQ entry there.
Quote:
Originally Posted by cwr
Sorry, I'm using windows 2000 pro and microsoft Visual C++ 2003 .NET