First of all, thanks for the Windows port of pdcurses. It's just what I was looking for.
I'm having trouble with the getch () function getting "backlogged".
Normally, inputting keys using getch works fine. However, if I type in keys when my program isn't ready (in my case, during disk access), the keys get queued. Then, when I call getch, it waits until I press a key and then returns one of the keys from the queue instead of the one I pressed.
Is there a way to clear this keyboard queue or buffer? I found the function flushinp, which sounded promising, but calling flushinp before getch hasn't solved my problem.
If it helps, this is part of the code I use to initialize pdcurses:
// Open the display
initscr (); // Initialize the curses library
// Set i/o attributes
attron (A_ALTCHARSET); // Allow extended ASCII characters
start_color (); // enable color
keypad (stdscr, TRUE); // Enable keyboard mapping
nonl (); // No NL->CR on output
cbreak (); // input one char at a time
noecho (); // dont echo input
curs_set (0); // hide the cursor
// Make sure the terminal supports color
if(has_colors() == FALSE)
std::cerr << "Your terminal does not support color" << std::endl;
I then go on to define the colors to be used.
Oh, BTW, "attron(A_ALTCHARSET)" will be a disaster under PDCurses 3.0. (Under any version of ncurses, too.) But that shouldn't have anything to do with your input problem.
If you're trying to print characters in the range 128-255, you don't need to do anything special. (Except: make sure you don't get an unwanted sign extension by passing a negative char value directly to addch(). Convert it first, e.g., via an (unsigned char) cast.) If you're trying to print characters in the range 0-31, you can either | A_ALTCHARSET with the character, or use the addraw* functions.
Thanks, but no, it doesn't help. If you can provide a complete program that illustrates the problem (preferably, the smallest possible program that does so), that might help.
flushinp() is indeed the correct and only way to discard queued keystrokes. Note that it wasn't implemented for Win32 until PDCurses 2.8.
The problem you describe isn't familiar to me, but I'll see if I can reproduce it.
So far, I can't reproduce this. getch() and flushinp() are both working as expected for me (with both 2.8 and pre-3.0).
Oh, and to clarify, "working as expected" means this:
1. Type some characters while the program is doing something else. Call getch(). It returns immediately (NOT after you press another key) with the first queued character.
2. Type some characters while the program is doing something else. Call flushinp(). Call getch(). It waits for the next character you type, and returns that.
Thanks for the tip about attron(A_ALTCHARSET).
I'll work on a simple demonstration of the problem. That should have been my first step, of course. It may solve my problem all together.
Thanks for taking the time to help.
Okay, I really feel rather embarassed now.
I'm trying to use pdcurses with Visual Studio 2005 Express. Of course, the version I downloaded here doesn't work with Visual Studio 2005 because the single threaded libraries don't exist. Being far too lazy to rebuild the library myself, I found a DLL compiled by... somebody else... somewhere. I suspect this may be where my problem lies.
I'll try to get off my lazy posterior and compile the curses library myself and see if that makes a difference. Barring that, I may just try using another development environment.
Thanks again for all the help.
Log in to post a comment.