- 1 year ago
Console with ~ENABLE_LINE_INPUT doesn't pass /r
When you set the ENABLE_LINE_INPUT
mode for the console input in Windows, the input is processed line by line, which means the Enter key (\r
) is considered a line terminator. Therefore, it is not directly passed to the console input buffer.
However, you can modify the console mode to handle the Enter key (\r
) differently. You can use the ENABLE_PROCESSED_INPUT
flag in combination with ENABLE_LINE_INPUT
to achieve this. The ENABLE_PROCESSED_INPUT
mode allows you to receive special keys, such as Ctrl+C or Ctrl+Break, and control characters like Enter (\r
) in the input buffer.
Here's how you can set the console mode to include ENABLE_LINE_INPUT
and ENABLE_PROCESSED_INPUT
:
c#include <Windows.h>
int main() {
HANDLE hInput = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode;
GetConsoleMode(hInput, &mode);
mode |= ENABLE_LINE_INPUT | ENABLE_PROCESSED_INPUT;
SetConsoleMode(hInput, mode);
// Now you can read input line by line using ReadConsole
return 0;
}
With the above settings, when you read input using ReadConsole
, the Enter key (\r
) will be processed as a control character, but other characters will be passed to the input buffer until the Enter key is pressed, forming a line of input.
Keep in mind that this will affect how you read input from the console, and you may need to adjust your input handling accordingly. For example, you may need to handle the \r
character separately to implement custom behavior when the Enter key is pressed.