c语言键盘ESC退出其他键继续输出

2025-04-07 06:08:11
推荐回答(4个)
回答1:

用 GetAsyncKetState 函数吧:

#include 

#define KEYDOWN( vk ) ( 0x8000 & ::GetAsyncKeyState( vk ) )

while( true )
{
    if( KEYDOWN( VK_ESCAPE ) )
    {
        exit( 0 );
    }
    else
    {
        // TODO : 在此处放置你的代码 ...
    }
}

回答2:

按ESC不会因为不清楚是什么状况一般情况是一直输出q直到你输入一个特定的字符串停止
例如if(!strcmp(“quit”,getchar()))

回答3:

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");
}

回答4:

ESC的ascii码是什么忘了,可以用个if语句不就行了