mirror of
https://github.com/sockspls/badfish
synced 2025-04-29 16:23:09 +00: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:
parent
5c4f6f6226
commit
95ce27f926
1 changed files with 17 additions and 1 deletions
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
|
||||
|
|
Loading…
Add table
Reference in a new issue