Skip to content

Commit

Permalink
fix: Pressing any key won't exit consolepauser in windows
Browse files Browse the repository at this point in the history
  • Loading branch information
royqh1979 committed Dec 26, 2024
1 parent 579baba commit edbaf17
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tools/consolepauser/main.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ void PrintWin32ApiError(const wchar_t *function)
void PauseExit(int exitcode, bool reInp) {
if (pauseBeforeExit) {
HANDLE hInp=NULL;
INPUT_RECORD irec;
DWORD cc;
if (reInp) {
SECURITY_ATTRIBUTES sa;
sa.nLength = sizeof(sa);
Expand All @@ -169,9 +171,15 @@ void PauseExit(int exitcode, bool reInp) {
const wchar_t* pause_msg = getMessageFromEnv("RCP_EXIT_MSG",L"Press ANY key to exit...");
PrintToStdout(L"\n");
PrintToStdout(pause_msg);
wchar_t buffer[2];
DWORD nRead;
ReadConsoleW(hInp, buffer, 1, &nRead, NULL);
for(;;)
{
ReadConsoleInput(hInp, &irec, 1, &cc );
if( irec.EventType == KEY_EVENT
&& ((KEY_EVENT_RECORD&)irec.Event).bKeyDown
) {
break;
}
}
if (reInp) {
CloseHandle(hInp);
}
Expand Down

0 comments on commit edbaf17

Please sign in to comment.