#include <windows.h>
#include <conio.h>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
int press()
{
int i;
for(i=0;i<256;i++)
if(GetAsyncKeyState(i)<0&&i>2)
return 1;
return 0;
}
int main()
{
char pressdown=0,str[50];
int i=0;
long timepass=1,start,finish;
Sleep(100);
start=clock();
while(timepass<30000)
{
printf("\rtime-left %2ds. input a key:",(30000-timepass)/1000+1);
if(press()){pressdown=1;break;}
Sleep(100);
timepass=clock()-start;
}
if(pressdown)
{
while((str[i++]=getchar())!='\n');
str[i]='\0';
printf("\n The keys you pressed is %s \n ",str);
}
else
printf("\rtime-left
0s. input a key: \n times up!\n");
system("pause");
return
0;
}