Thread: Problem with keyboard Input.

  1. #1
    Registered User actionbasti's Avatar
    Join Date
    Dec 2002
    Posts
    48

    Problem with keyboard Input.

    Hi everybody...
    happy thanksgiving!

    Here is my problem. I am making this classic game, a clone of asteroids you could say. Well you controll an aircraft, view from top and you shoot at enemies that come at you from top of the screen.
    If you play the game, then you will recognize that the control doesnt work all the way. Its possible to manuver in all directions( using arrow keys); however if you press the spacebar to shoot the laser, then all directions work except the upper left.

    So, pressing space, left, and up at the same time doesnt work. Can anyone help me figure out why?

    Code:
    void HandleKeys()
    {
    	
        if (GetKeyState(VK_RIGHT) < 0)
    		strider.posX = strider.posX + 4;
    	if (GetKeyState(VK_LEFT) < 0)
    		strider.posX = strider.posX - 4;
        if (GetKeyState(VK_UP) < 0)
    		strider.posY = strider.posY - 4;
    	if (GetKeyState(VK_DOWN) < 0)
    		strider.posY = strider.posY + 4; 
    }
    To better understand, here is the complete source code for .NET c++
    thank you!

  2. #2
    Registered User
    Join Date
    Jun 2003
    Posts
    17
    I'm using visual c++ 6 so I can't run the program to my knowledge without an executable because I don't know what lib file to include.

    But instead of

    Code:
    if (GetKeyState(VK_RIGHT) < 0)
    try for all the if statements

    Code:
    if(GetAsyncKeyState(VK_RIGHT))
    this will return a true or false value

    This may not work, but it's worth a try.

  3. #3
    Registered User actionbasti's Avatar
    Join Date
    Dec 2002
    Posts
    48
    Originally posted by Jontay
    I'm using visual c++ 6 so I can't run the program to my knowledge without an executable because I don't know what lib file to include.
    I include the following lib file to make transparancy work:
    msimg32.lib


    Originally posted by Jontay
    Code:
    if(GetAsyncKeyState(VK_RIGHT))
    I Started With GetAsyncKeyState(VK_...), so that is not the problem either!

    I tried the game on several computers and everywhere its the same, so I realy dont know what it could be! :-( help!!

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