17.3.4 Modes for the Console Functions

For the Console functions, the relevant input modes are mouse aware and window aware. By default, input handles are created with both modes enabled. With one exception, line, processed, and echo input modes have no effect on applications using the Console functions, since the console input buffer always receives all keyboard input (raw mode) and input is only echoed when applications call ReadFile. The exception is that if processed input is enabled, Ctrl-C characters are passed to the control handler functions; if disabled, they are placed as ASCII characters into the input buffer. Mouse aware and window aware modes have no effect on applications using the File functions, since ReadFile returns only keyboard input, discarding any mouse or buffer size events.

The following code fragment gets the current console mode and then modifies it to filter out mouse events:

ULONG Mode;

HANDLE hStdIn = GetStdHandle(STD_INPUT_HANDLE);

BOOL bSuccess;

/* get the current mode */

bSuccess = GetConsoleMode(hStdIn,&Mode);

if (!bSuccess) {

/* handle error */

}

/* turn off mouse input */

Mode &= ~ENABLE_MOUSE_INPUT;

bSuccess = SetConsoleMode(hStdIn,Mode);

if (!bSuccess) {

/* handle error */

}