This message was edited by Lundin at 2004-7-6 7:23:7
: yes,
: if i read more character that removes also new-line characters...
:
: but i don't want to use workarounds because next time i will do something i don't now what will happen...
:
: and the problem not only in flush method but the new-line characters should not be put to input buffer according to docs
:
: i talked to someone on IRC and he also was puzzled...
: he even tried something else...
: first he called FlushConsoleInputBuffer() and then called GetNumberOfConsoleInputEvents() and it returned non-zero result...
:
: could it be a ms bug?
:
:
I tried your code and I also think that this is a bug.
FlushConsoleInputBuffer() isn't following the function spec:
"The FlushConsoleInputBuffer function flushes the console input buffer. All input records currently in the input buffer are discarded."
Well, CR+LF are obviously not discarded.
Here is the code I tried it with:
(same result with both gcc & Borland)
while (1)
{
DWORD x;
WriteConsole(hStdout, "\npress [1] for codepage: ", 25, &x, NULL);
if(WaitForSingleObject(hStdin,INFINITE)==WAIT_OBJECT_0)
{
ReadConsole(hStdin,buf,1,&x,NULL);
while(!FlushConsoleInputBuffer(hStdin))
;
GetNumberOfConsoleInputEvents(hStdin,&x);
cout << x << endl; // I get 0 here
}
}