I think the key is that the first time it reads "quit" (and every poll before that), it is returning BiosKey()=TRUE via the "#C" path below, but then whenever I check BiosKey() after that, it continues to return TRUE, but via the "#B" path.
Is the
- Code: Select all
if (!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL)) {
fprintf(logStream,"#B");
return 1; }
Is this related to it being the end of game, and maybe the pipe being closed?
- Code: Select all
//ReadInput and Bioskey were copied from a snippet posted on the WinBoard forum
int XBoard=1; // Set to 1 for winboard, 0 for testing in console mode
int Bioskey(void) {
static int init = 0, pipe;
static HANDLE inh;
DWORD dw;
if (XBoard) {
if (!init) {
init = 1;
inh = GetStdHandle(STD_INPUT_HANDLE);
pipe = !GetConsoleMode(inh, &dw);
if (!pipe) {
SetConsoleMode(inh, dw & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT));
FlushConsoleInputBuffer(inh);
}
}
if (stdin->_cnt > 0) {
fprintf(logStream,"#A");
return stdin->_cnt;
}
if (pipe) {
if (!PeekNamedPipe(inh, NULL, 0, NULL, &dw, NULL)) {
fprintf(logStream,"#B");
// return 1;
return 0; // will this fix timing error?
}
fprintf(logStream,"#C");
return dw;
}
else {
GetNumberOfConsoleInputEvents(inh, &dw);
fprintf(logStream,"#D");
return dw <= 1 ? 0 : dw;
}
}
else {
fprintf(logStream,"#E");
return _kbhit();
}
}