Windows console input modes

What does line-buffering do in windows console (as in setting console input mode)?
What are the purposes of the various other modes? (I read them on the windows console functions website but some of them are downright confounding)
And is there a mode to accept arrow keys and combined keys, such as alt+x (example only)?
Did you check out this recent series of posts?

http://www.cplusplus.com/forum/windows/16988/


And is there a mode to accept arrow keys and combined keys, such as alt+x (example only)?


Yes. See examples above. As to the line buffering thing, that's when you want the function you call to return after typing in a line and hitting [ENTER]. The examples above don't work like that.
Which blocks of code are you referring to in the posts you referenced?
Those examples of mine (the ones using WaitForMultipleObject() and WaitForSingleObject()) don't use buffered input. If you want the type of line input type of data entry as you would have with the C Runtime stdio gets() (get string) function, you would have to use the SetConsoleMode function with the flag for line input mode.

If you want to just capture individual INPUT_RECORDs you can use code like mine. There you should be able to filter for anything odd you wish such as alt, ctrl, shift whatever combinations. It takes lots of work to become familiar with these console functions. Here is a link you might want to look at...

http://msdn.microsoft.com/en-us/library/ms685035(VS.85).aspx

I remember many years ago I downloaded piles of sample code from Microsoft on these console functions, but I don't have it anymore. One other thing...the PeekConsoleInput() function is particularly useful. Unlike ReadConsoleInput() it doesn't block; you can examine the key in the input record before deciding to 'read' it or not.
I wrote you a little program that shows line input (buffered type operation) mode. It just saves what you write into a lpBuffer variable, then outputs that line with WriteConsole after you hit the [ENTER] key. I set the read buffer to 128 bytes so don't enter a line longer than that. Also, whatever you type will be echoed to the screen as you type it.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <windows.h>

int main(void)
{
 HANDLE hStdInput,hStdOutput;
 DWORD nNumberOfCharsToRead=127;
 DWORD nRead,nWritten;
 char lpBuffer[128];

 memset(lpBuffer,0,128);
 hStdInput=GetStdHandle(STD_INPUT_HANDLE);
 hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
 SetConsoleMode(hStdInput,ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT);
 FlushConsoleInputBuffer(hStdInput);
 ReadConsole(hStdInput,lpBuffer,nNumberOfCharsToRead,&nRead,NULL);
 WriteConsole(hStdOutput,lpBuffer,nRead,&nWritten,0);

 return 0;
}
Topic archived. No new replies allowed.