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%.
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.
zen
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.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.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
GetAsyncKeyState() is a winapi func. thats been around a while.Try using that... Info on its use at msdn.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
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.