two buttons at the same time

This is a discussion on two buttons at the same time within the Game Programming forums, part of the General Programming Boards category; In my programm iam using a switch statment like you see in my code below. The problem is that i ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    21

    two buttons at the same time

    In my programm iam using a switch statment like you see in my code below. The problem is that i can only press one key, when i press both nothing happents... can anyone help me
    ? iam want to be able to press both buttens in at the same time.


    LRESULT CALLBACK
    WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam)
    {
    switch (uMsg)
    {
    case WM_DESTROY:
    Cleanup();
    PostQuitMessage(0);
    break;

    case WM_KEYDOWN:
    switch (wParam)
    {
    case VK_LEFT:
    if (move_rate>-300.0) move_rate-=60.0;
    break;

    case VK_UP:
    if(y_pos-5 > 0) y_pos=y_pos-5;
    break;


    case VK_ESCAPE:
    DestroyWindow(hWnd);
    break;

    default:
    break;
    }

    default:
    return DefWindowProc(hWnd, uMsg, wParam, lParam);
    }
    return 0L;
    }

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,267
    use something like nehe does

    http://nehe.gamedev.net

    Code:
    bool keys[256];
    
    LRESULT CALLBACK 
    WindowProc(HWND hWnd, unsigned uMsg, WPARAM wParam, LPARAM lParam)
    {
    
    //...
        case WM_KEYDOWN: 
            keys[wParam] = true;
        break;
    
        case WM_KEYUP:
            keys[wParam] = false;
        break;
    //...
    
    }
    then proccess the keys in you main loop:

    Code:
    if(keys[VK_ESCAPE])
        PostQuitMessage(0);
    
    if(keys[VK_UP])
        if(y_pos-5 > 0) y_pos=y_pos-5;
    
    if(keys[VK_LEFT])
        if (move_rate>-300.0) move_rate-=60.0;
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    21
    thank you that helped. by the way http://nehe.gamedev.net is an awesome webpage.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. Sending an email in C program
    By Moony in forum C Programming
    Replies: 28
    Last Post: 10-19-2006, 11:42 AM
  3. Is this really true or it's just science fiction?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 145
    Last Post: 04-09-2002, 07:17 PM
  4. time class
    By Unregistered in forum C++ Programming
    Replies: 1
    Last Post: 12-11-2001, 10:12 PM

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