Keyboard polling loop

This is a discussion on Keyboard polling loop within the C Programming forums, part of the General Programming Boards category; Anybody got a keyboard polling loop that doesn't hog the Win2000 CPU? I've been using while(!kbhit()) for years under DOS, ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    3

    Keyboard polling loop

    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%.

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You could call Sleep(millisecs) - in windows.h, within your loop if you want to keep it simple.
    zen

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    3
    Originally posted by zen
    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.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,749
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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

  6. #6
    Registered User
    Join Date
    Oct 2001
    Posts
    3
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. My loop within loop won't work
    By Ayreon in forum C Programming
    Replies: 3
    Last Post: 03-18-2009, 11:44 AM
  2. Visual Studio Express / Windows SDK?
    By cyberfish in forum C++ Programming
    Replies: 23
    Last Post: 01-22-2009, 02:13 AM
  3. syntax question
    By cyph1e in forum C Programming
    Replies: 19
    Last Post: 03-31-2006, 12:59 AM
  4. qwerty/azerty keyboard type problem + question about loop.
    By Robin Hood in forum C++ Programming
    Replies: 9
    Last Post: 07-22-2002, 02:03 PM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 09:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21