Hi cece,
Thx for your answere. But getchart don't solve my problem, because its a blocking function. This means, if no key is pressed, the function getchar blocks until a key is pressed. With kbhit it is possible just to test, if an key was pressed(without blocking).
-> with the help of <termios.h> it should be possible to programm a kbhit function, but the functions :
- tcgetatt
- tcsetattr
from termios.h doesnt't work ??? Any other solutions are welcome
Here the code :
int getch()
{
static int ch = -1, fd = 0;
struct termios neu, alt;
fd = fileno(stdin);
tcgetattr(fd, &alt);
neu = alt;
neu.c_lflag &= ~(ICANON|ECHO);
tcsetattr(fd, TCSANOW, &neu);
ch = getchar();
tcsetattr(fd, TCSANOW, &alt);
return ch;
}
int kbhit(void)
{
struct termios term, oterm;
int fd = 0;
int c = 0;
tcgetattr(fd, &oterm);
memcpy(&term, &oterm, sizeof(term));
}