Click here to Skip to main content
15,845,469 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
	SetConsoleMode(hStdInput , ENABLE_WINDOW_INPUT);

		iCount = GetTickCount();
		if (ReadConsoleInput(hStdInput,ir,128,&nRead))
			iCount = GetTickCount()-iCount;
			if (iCount>100)
				printf("Slow = %d\r\n", iCount);
				printf("%d\r\n", iCount);
			if (ir[0].EventType ==KEY_EVENT && ir[0].Event.KeyEvent.wVirtualKeyCode==VK_ESCAPE)
	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
Updated 26-Feb-23 5:44am

1 solution

According to Microsoft documentation, the system call is not suitable for Win9x.

Minimum supported client is Windows 2000 Prof

Since Win9x does not support preemptive multitasking, you would need a non-blocking alterative to ReadConsoleInput(). This is discussed e.g. here: non-blocking-readconsoleinput

The GetNumberOfConsoleInputEvents() function is recommended here, although it is also only documented from Windows 2000 Prof. onwards.
Share this answer
uuu99933 26-Feb-23 11:37am    
Older help versions state: ReadConsoleInput function available starting in Windows 95
It's just that Microsoft is erasing references to older systems.
Above I wrote that I tried both GetNumberOfConsoleInputEvents and PeekConsoleInput and WaitForSingleObject , but it did not help.
For some reason, the function sometimes slows down for longer periods of time than usual. Usually 30-80ms, but about every 15-20 returns it runs 300-600ms

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900