I have something like this:
keypad(stdscr, TRUE);
nodelay(stdscr, TRUE);
char key;
while(1)
{
usleep(80000);
// ...Program related code...
// Key Listener
key = getch();
switch (key)
{
case 'a':
// a related code
break;
case 'b':
// b related code
break;
}
}
However I'm noticing some strange behaviour where if I hit the a
, and b
keys fast enough, (faster than the tick rate), they appear to be buffered by getch(), as with every subsequent tick, the program will continue to process those a
and b
presses until the buffer catches up. So if you hold down one of the keys, it will continue to be processed by getch() long after you have lifted off of the key.
I only want one key to be sampled and processed per tick. I don't want getch to asynchronously buffer keypresses. Is there a way to clear the buffer, or perhaps disable the extra buffering of getch so that it only stores the last pressed character?