How to use keys in OpenGL and Windows - Programmers Heaven

Howdy, Stranger!

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

Categories

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.