Anybody got a keyboard polling loop that doesn't hog the Win2000 CPU?
I've been using while(!kbhit()) for years under DOS, Win9x and even OS/2's VDM. But Win2k's VDM pegs CPU usage at 100%.
Printable View
Anybody got a keyboard polling loop that doesn't hog the Win2000 CPU?
I've been using while(!kbhit()) for years under DOS, Win9x and even OS/2's VDM. But Win2k's VDM pegs CPU usage at 100%.
You could call Sleep(millisecs) - in windows.h, within your loop if you want to keep it simple.
I tried this, but it didn't help. Mebbe because I'm using an old Watcom compiler (32-bit extended DOS)? And Watcom's sleep() takes seconds in place of millisecs.Quote:
Originally posted by zen
You could call Sleep(millisecs) - in windows.h, within your loop if you want to keep it simple.
> Mebbe because I'm using an old Watcom compiler (32-bit extended DOS)?
Since this was written way before win2K (and perhaps even before NT4), then I'd say this is at least part of the problem.
GetAsyncKeyState() is a winapi func. thats been around a while.Try using that... Info on its use at msdn.
Got a solution to my kbhit() hogging the Win2K CPU problem from the powersoft.public.watcom_c_c++.general newsgroup. It involves setting up a real-mode interrupt under DOS4GW, then calling 0x2F with ax=1680.
Tricky stuff, but thanks to all those who pitched in with suggestions. If anybody would like the code fragment that does the job, just holler.