diff options
Diffstat (limited to 'libguile/posix-w32.c')
-rw-r--r-- | libguile/posix-w32.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libguile/posix-w32.c b/libguile/posix-w32.c index 5f6c0b759..239fd1156 100644 --- a/libguile/posix-w32.c +++ b/libguile/posix-w32.c @@ -289,6 +289,54 @@ dlerror_w32 () snprintf (dlerror_str, DLERROR_LEN, "error %ld: %s", (long) dw, msg_buf); return dlerror_str; } + +/* Check for the Windows 11 bug where there's a return character in the + * console input queue despite draining the input. */ +int +console_has_return_keyevent_w32 (int fdes) +{ + HANDLE h; + DWORD mode; + + h = (HANDLE) _get_osfhandle (fdes); + if (h == -1) + return 0; + if (GetConsoleMode (h, &mode) == 0) + return 0; + + // Rarely need more than 1 INPUT_RECORD for this test, but just in + // case there is a mouse event in the queue. +#define NBUFFER 8 + INPUT_RECORD irbuffer[NBUFFER]; + BOOL bRet; + DWORD avail; + int i; + int n_chars = 0; + int n_returns = 0; + + while (1) + { + bRet = PeekConsoleInput (h, irbuffer, NBUFFER, &avail); + if (!bRet || avail == 0) + break; + + for (i = 0; i < avail; i++) + if (irbuffer[i].EventType == KEY_EVENT) + { + n_chars ++; + if (irbuffer[i].Event.KeyEvent.uChar.AsciiChar == 13) + n_returns ++; + } + if (avail < NBUFFER) + break; + } + + if (n_chars == 1 && n_returns == 1) + return 1; + return 0; +#undef NBUFFER +} + int getpagesize_w32 (void) { |