unblocking getch() in loop
Aug 26, 2015 at 7:08am UTC
i am try to test the function by looping it until the key 'A' is pressed, however, getch() is blocking the looping, what should i modify so that the program work?
here is my code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
#include <iostream>
#include <ncurses.h>
using namespace std;
int kbhit()
{
char ch = getch();
if (ch !=ERR)
{
ungetch(ch);
return 1;
}
else
{
return 0;
}
}
int main()
{
initscr();
for (long index = 0; index < 100000; index ++)
{
cout << index << endl;
system("stty raw" );
if (kbhit())
{
if (getch() == 'a' )
{
system("stty cooked" );
break ;
}
}
system("stty cooked" );
}
cout << "End of program" << endl;
endwin();
}
Topic archived. No new replies allowed.