1

Let's consider that example:

#include <ncurses.h>
#include <unistd.h>


// ...
// Some functions like `contains` and `getBuff`
// ...

int main() {
  initscr();                        // Init curses mode
  // ... Do some initialisation

  int *input;                       // Input buffer

  while(1) {
    getBuff(input);                 // Get all characters currently available into buffer
    if(contains(input, 'q')) break; // If there is 'q' in buffer - break
    // ... Do something with buffer
    usleep(100000);                 // Wait some time
  }

  endwin();                         // Exit curses
  return 0;
}

Here, in the loop the program waits some time, and after it gets all input got while it was sleeping.
The main problem is in getBuff() — I don't know how to make it.

I've tried using halfdelay() and while(getch() != ERR), but it doesn't work fine. If the user presses any key and does not release it, the program stops at the loop.

So, getBuff() might get all input available at the time of its call, not later.

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
ISD
  • 984
  • 1
  • 6
  • 21
  • Does the linked duplicate answer your question? [Create a function to check for key press in unix using ncurses](https://stackoverflow.com/questions/4025891/create-a-function-to-check-for-key-press-in-unix-using-ncurses). If not, could you explain what it's missing? – John Kugelman Jan 17 '21 at 11:12
  • @JohnKugelman No, it's not duplicate. In their case they were not getting currently available at buffer. They were continuously getting input even after the old buffer was fully red. – ISD Jan 17 '21 at 11:14
  • 1
    I'm not sure I follow. You said `halfdelay()` didn't work. What about `nodelay()`? – John Kugelman Jan 17 '21 at 11:16
  • Perhaps no. It works the same — it reads input while it sees something. – ISD Jan 17 '21 at 11:18
  • 1
    Could you show your code using `nodelay()`? Let's figure out why it isn't working for you. – John Kugelman Jan 17 '21 at 11:22
  • The suggested duplicate is incorrect. [This one](https://stackoverflow.com/questions/56245062/what-is-the-difference-between-nodelay-and-cbreak-in-ncurses/56245112#56245112) is more appropriate. – Thomas Dickey Jan 17 '21 at 11:32
  • Looks like `nodelay()` is working. But both "duplicate questions" seems not a duplicate, even if the answers help. Thanks for help! – ISD Jan 17 '21 at 11:43

0 Answers0