mirror of
https://github.com/HChaZZY/Stockfish.git
synced 2025-12-19 16:46:30 +08:00
Ignore non keyboard events in Bioskey()
Filter out mouse and windows type events. This fix an issue where Glaurung hangs in console mode under Windows. To reproduce simply open a console under Windows (cmd.exe), run "glaurung.exe bench 50 1", this starts benchmarking. Then hide the windows and show again or clik the mouse somewhere on the window, this hangs the benchmark because Boiskey() returns true and poll() calls std::getline() that hangs waiting for user pressing a return key. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
18
src/misc.cpp
18
src/misc.cpp
@@ -178,8 +178,24 @@ int Bioskey()
|
||||
return 1;
|
||||
return dw;
|
||||
} else {
|
||||
// Count the number of unread input records, including keyboard,
|
||||
// mouse, and window-resizing input records.
|
||||
GetNumberOfConsoleInputEvents(inh, &dw);
|
||||
return dw <= 1 ? 0 : dw;
|
||||
if (dw <= 0)
|
||||
return 0;
|
||||
|
||||
// Read data from console without removing it from the buffer
|
||||
INPUT_RECORD rec[256];
|
||||
DWORD recCnt;
|
||||
if (!PeekConsoleInput(inh, rec, Min(dw, 256), &recCnt))
|
||||
return 0;
|
||||
|
||||
// Search for at least one keyboard event
|
||||
for (DWORD i = 0; i < recCnt; i++)
|
||||
if (rec[i].EventType == KEY_EVENT)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user