i am using Mac os X, which running Unix system. i had tried getch() function which can't work in this case. I am wondering is that any method to make the function wait for an input without blocking? Thank you
Here is the code:
Here is the code:
Code:
#include <iostream>
#include <curses.h>
// checks if a key a has been pressed(non-blocking)
int kbhit()
{
int ch;
//getchar();
ch = getch();
//ch = 'a';
//system("stty cbreak -echo");
if (ch != ERR) {
//ungetch(ch);
return 1;
} else {
return 0;
}
}
using namespace std;
int main()
{
bool gameover = false;
nodelay(stdscr, TRUE);
//system("stty raw");
while(!gameover)
{
if(kbhit())
{
cout << "You enter something" << endl;
cout << kbhit() << endl;
gameover = true;
}
else
{
cout << "nothing is enter\n";
cout << kbhit() << endl;
gameover = false;
}
}
//system ("stty cooked");
//system("stty cooked echo");
return 0;
}
Last edited by a moderator: