Hi all!
Are there people who write or wrote on Win9x?
I have a question about the function ReadConsoleInput in console.
For some reason, on Win9x systems, random stutters occur when this function returns. The difference can be up to 10 times (from 30ms to 600ms).
This occurs when a key is pressed and held. Here is the simplest code that behaves like this on Win9x:
#include <windows.h>
#include <stdio.h>
int main(void)
{
HANDLE hStdInput,hStdOutput;
INPUT_RECORD ir[128];
DWORD nRead;
int blnLoop=1;
int iCount;
hStdInput=GetStdHandle(STD_INPUT_HANDLE);
hStdOutput=GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleMode(hStdInput , ENABLE_WINDOW_INPUT);
FlushConsoleInputBuffer(hStdInput);
do
{
iCount = GetTickCount();
if (ReadConsoleInput(hStdInput,ir,128,&nRead))
{
iCount = GetTickCount()-iCount;
if (iCount>100)
{
printf("Slow = %d\r\n", iCount);
}
else
{
printf("%d\r\n", iCount);
}
if (ir[0].EventType ==KEY_EVENT && ir[0].Event.KeyEvent.wVirtualKeyCode==VK_ESCAPE)
blnLoop=0;
};
}
while (blnLoop==1);
return 0;
}
P.S. On windows 2000 and above, there are no such problems.
What I have tried:
1) Change ReadConsoleInput to PeekConsoleInput+FlushConsoleInputBuffer
2) Simply add additionally to the beginning and / or to the end of FlushConsoleInputBuffer for additional buffer clearing
3) Set the number of received records not 128, but more or less up to one
4) Added WaitForSingleObject to trigger an event on it
5) Added GetNumberOfConsoleInputEvents to know how many events are in the buffer and exactly how many calls ReadConsoleInput made
6) Changed the creation of the GetStdHandle handle to CreateFile
7) Removed GetTickCount and just watched the result of output lines
Nothing helped. The problem of random input freeze remained
tests were carried out on virtual systems and on a real computer