#include <stdio.h>
#include <conio.h>
#include <time.h>
// Espera que seja pressionada uma
// tecla durante 'delay' segundos
char DelayGetch(int delay)
{
clock_t start;
start = clock();
while(((clock() - start) / CLK_TCK) < delay)
if(kbhit())
return getch();
return -1;
}
void main()
{
char ch;
printf("Digite uma tecla\n");
do{
ch = DelayGetch(5);
if(ch == -1)
printf("\nTempo esgotado\n");
else
putch(ch);
}while(ch != -1 && ch != 27);
}