Thread: Problem getting input from keyboard

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    118

    Problem getting input from keyboard

    Here is the code Im using right now
    Code:
            if (GetAsyncKeyState(VK_UP) & SHRT_MAX) gUpKey = true;
    	else gUpKey = false;
            if (GetAsyncKeyState(VK_LEFT) & SHRT_MAX) gLeftKey = true;
    	else gLeftKey = false;
            if (GetAsyncKeyState(VK_DOWN) & SHRT_MAX) gDownKey = true;
    	else gDownKey = false;
            if (GetAsyncKeyState(VK_RIGHT)& SHRT_MAX) gRightKey = true;
    	else gRightKey = false;
    The problem if that if I press and hold down a key it kind of gets pressed, then waits for a second, and then is continually pressed... I dont know how to explain it better does anyone know what Im talking about?
    Example: in notepad press and hold a key and you will see what Im talking about. How can I fix this problem?
    Why drink and drive when you can smoke and fly?

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,057
    Every loop of your program, set all the variables like gUpKey to false. Just before you read them in.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  3. #3
    Registered User
    Join Date
    Jan 2003
    Posts
    118
    You mean like this?
    Code:
            gUpKey = gLeftKey = gDownKey = gRightKey = false;
            if (GetAsyncKeyState(VK_UP) & SHRT_MAX) gUpKey = true;
    	else gUpKey = false;
            if (GetAsyncKeyState(VK_LEFT) & SHRT_MAX) gLeftKey = true;
    	else gLeftKey = false;
            if (GetAsyncKeyState(VK_DOWN) & SHRT_MAX) gDownKey = true;
    	else gDownKey = false;
            if (GetAsyncKeyState(VK_RIGHT)& SHRT_MAX) gRightKey = true;
    	else gRightKey = false;
    Because thats not working...
    Why drink and drive when you can smoke and fly?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem getting the input from a temp variable into the Array
    By hello_moto in forum C++ Programming
    Replies: 3
    Last Post: 03-16-2006, 01:50 AM
  2. problem : input and calculation working together
    By itay390 in forum C Programming
    Replies: 13
    Last Post: 07-30-2005, 12:32 PM
  3. Need help with keyboard input
    By wiramu in forum C++ Programming
    Replies: 2
    Last Post: 11-28-2003, 02:44 PM
  4. FAQ Keyboard Input ? (C++)
    By Malikive in forum FAQ Board
    Replies: 6
    Last Post: 11-07-2001, 09:30 PM
  5. Keyboard input ?
    By Malikive in forum Game Programming
    Replies: 4
    Last Post: 11-06-2001, 11:14 PM