getch, nodelay, extended curses

From: Charris (chrisandharris_at_gmail.com)
Date: 09/29/05


Date: 29 Sep 2005 11:26:42 -0700

Hello AIX crew,

Having some strange behavior with extended curses (-lcur) I can't seem
to resolve. Recently we started using nodelay(stdscr, ) in conjuction
with getch(). We've had no problems with getch till this point with
the BACKSPACE key (code 263 with libcur), but when we use nodelay(),
the backspace key returns intermittently, sometimes returning 263,
other times just sitting with a -2 (no key pressed) code.

I've compiled some tests, 1. I compiled with gnu ncurses, works
perfectly. 2. Compiled a test with standard curses libcurses, it
returns 0x8 consistently with no problems. Even the following code by
Floyd Davidson does not always catch the backspace key all the time:

int
kbhit(void)
{
  int cnt = 0;
  int error;
  static struct termios Otty, Ntty;

  tcgetattr(0, &Otty);
  Ntty = Otty;

  Ntty.c_iflag = 0; /* input mode */
  Ntty.c_oflag = 0; /* output mode */
  Ntty.c_lflag &= ~ICANON; /* line mode */
  Ntty.c_cc[VMIN] = CMIN; /* minimum time to wait */
  Ntty.c_cc[VTIME] = CTIME; /* minimum characters to wait for */

 if (0 == (error = tcsetattr(0, TCSANOW, &Ntty))) {
    struct timeval tv;
    tv.tv_sec = 0;
    tv.tv_usec = 100;
    select(1, NULL, NULL, NULL, &tv); /* a small time delay */
    struct timeval tv;
    error += ioctl(0, FIONREAD, &cnt);
    error += tcsetattr(0, TCSANOW, &Otty);
  }
  return (error == 0 ? cnt : -1 );

}

Anyone have any ideas?

TIA greatly
charris