Pular para o conteúdo

kbhit() no linux ????

Responder tópico
  • Denunciar
  • Indicar

1. kbhit() no linux ????

Enviado em 04/11/2006 - 21:53h

qual a funçao que eu uso que tem o mesmo efeito da kbhit() do DOS ...... eu pesquisei sobre a has_key() mas não consegui usar ela.... como eu uso em qual biblioteca esta?
me ajuda com um exemplo valew....

Responder tópico

2. antes tarde.... doque mais tarde rsrsrs

Enviado em 07/06/2012 - 00:41h


#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <fcntl.h>

int kbhit(void)
{
struct termios oldt, newt;
int ch;
int oldf;

tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
oldf = fcntl(STDIN_FILENO, F_GETFL, 0);
fcntl(STDIN_FILENO, F_SETFL, oldf | O_NONBLOCK);

ch = getchar();

tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
fcntl(STDIN_FILENO, F_SETFL, oldf);

if(ch != EOF)
{
ungetc(ch, stdin);
return 1;
}

return 0;
}

int main(void)
{
while(!kbhit())
puts("aperte qualquer tecla!");
printf("Vc apertou '%c'!\n", getchar());
return 0;
}

Responder tópico

Responder tópico

Entre na sua conta para responder.

Fazer login para responder