用 GetAsyncKetState 函数吧:
#include
#define KEYDOWN( vk ) ( 0x8000 & ::GetAsyncKeyState( vk ) )
while( true )
{
if( KEYDOWN( VK_ESCAPE ) )
{
exit( 0 );
}
else
{
// TODO : 在此处放置你的代码 ...
}
}
按ESC不会因为不清楚是什么状况一般情况是一直输出q直到你输入一个特定的字符串停止
例如if(!strcmp(“quit”,getchar()))
printf("|Press esc to quit, Press any other key to continue|\n");
i=0;
while(~scanf("%c",&r))//Enter ' ' and '\n' will print q one by one, because both of them can be taken as char
{
printf("Execute time is %ld\n",i++);
if(r==0x1b){break;return 0;}
printf("\n|Press esc to quit, Press any other key to continue|\n");
}
printf("end");
}
ESC的ascii码是什么忘了,可以用个if语句不就行了