I want to write simple function that allows me to stop my console program by pressing any key,while the whole program works in the 'background'
Decided to use termios.h
because I had some problems with lncurses.h
.I finished my function and it works kinda well but I have problem to stop it by pressing any key.
int main()
{
int key;
for (;;) {
key = getkey();
if (key !='\0') {
//also tried if (key != NULL) and if (key != 0x00)
break;
}else {
//do some stuff in loop till any key is pressed
}
}
return 0;
}
So far I can stop program by pressing any earlier declared key,for instance
if (key =='q' || key =='w')
.
I know I can declared every key and in that way make it work,but im sure there is better way to do that.Thanks