Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to use keys in OpenGL and Windows

JBW2k2JBW2k2 Posts: 6Member
Hi, i know that you can figure out what keys are being pressed with functions like WM_KEYDOWN, but how can you find out which key is being pressed; what are the values for a 256 bool vector just in asci code?

Comments

  • SephirothSephiroth Fayetteville, NC, USAPosts: 1,035Member
    : Hi, i know that you can figure out what keys are being pressed with functions like WM_KEYDOWN, but how can you find out which key is being pressed; what are the values for a 256 bool vector just in asci code?
    :
    The way my software key-stroke app works is this:
    [code]
    bool Keys[256];

    LRESULT CALLBACK MainCalls(HWND CallWnd, UINT CallMSG, WPARAM CallWP, LPARAM CallLP)
    {
    switch(CallMSG)
    {
    case WM_KEYDOWN:
    Keys[CallWP] = true;
    return 0;

    case WM_KEYUP:
    Keys[CallWP] = false;
    return 0;
    }
    return DefWindowProc(CallWnd, CallMSG, CallWP, CallLP);
    }

    int WINAPI WinMain(...)
    {
    ...
    //Inside your main loop
    if(Keys['A'])
    {
    //Handle A being pressed
    }

    if(Keys[VK_CONTROL])
    {
    //Handle control being pressed
    }
    ...
    return Message.wParam;
    }
    [/code]
    Simple, eh?

    -[italic][b][red]S[/red][purple]e[/purple][blue]p[/blue][green]h[/green][red]i[/red][purple]r[/purple][blue]o[/blue][green]t[/green][red]h[/red][/b][/italic]

Sign In or Register to comment.