In function boo()
I press a key, then the function doSthTimeConsuming()
is called.
Now I am pressing keys during doSthTimeConsuming()
.
Problem is that keys are buffered and in the next iteration boo()
will already have an input.
Could I clear or disable buffering for the keyboard in boo()
first?
void boo()
{
while(1)
{
c = getch();
switch(c)
...
break;
}
}
void doSthTimeConsuming()
{
usleep(1000000);
}
int main()
{
WINDOW* main_win = initscr();
cbreak();
noecho();
keypad(main_win, TRUE);
while(1)
{
boo();
doSthTimeConsuming();
}
return 0;
}
EDIT:
I found a workaround but i am still looking for solution with clearing the buffer.
A keyboard buffer is a section of computer memory used to hold keystrokes before they are processed. Keyboard buffers have long been used in command-line processing. As a user enters a command, they see it echoed on their terminal and can edit it before it is processed by the computer.
A keyboard buffer is a small area in the computer's memory (RAM) that is used to temporarily store the keystrokes from the keyboard before they are processed by the CPU.
The buffer is composed of 16 2-byte entries. It holds up to 16 keystrokes until they are read via the BIOS services through interrupt 22 (16 hex).
There is a function for this very purpose: flushinp()
http://pubs.opengroup.org/onlinepubs/007908799/xcurses/flushinp.html
I resolve the problem using keypad(main_win, FALSE);
after input is received and enabling it keypad(main_win, TRUE);
when it's needed.
void boo()
{
keypad(main_win, TRUE);
while(1)
{
c = getch();
switch(c)
...
break;
}
keypad(main_win, FALSE);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With