Jump to content
  • Advertisement
Sign in to follow this  
NLScotty

Handle input

This topic is 1001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

I am coding my own engine, for fun, in C++ and dx11. It is only a 2d engine, so not a very big deal. Tho I am wondering what the best way for input is. I came up with a solution like this (Stole the code from sfml)

Normal keys (skills, chat, jumping etc)

case WM_KEYDOWN:
        case WM_SYSKEYDOWN:
        {
            if (m_repeat || ((HIWORD(lParam) & KF_REPEAT) == 0))
            {
                // push the event onto the stack
            }
            break;
        }

        // Keyup event
        case WM_KEYUP:
        case WM_SYSKEYUP:
        {
            // push event onto the stack, doubt i will need this much tho
        }


// use this for moving and maybe some special cases (skills), my game can check for keys manally like
bool InputImpl::isKeyPressed(Keyboard::Key key)
{
    int vkey = 0;
    switch (key)
    {
        default:                   vkey = 0;             break;
        case Keyboard::A:          vkey = 'A';           break;
       
    }

    return (GetAsyncKeyState(vkey) & 0x8000) != 0;
}

Since it is only 2d and raw input seemed to be a lot more irritating, is this a fine solution?

 

gr

Share this post


Link to post
Share on other sites
Advertisement

Why don't you use sfml instead?  It's perfect for 2d games, and it has abstracted out input, audio, windows, views, network, etc. already for you and you don't have to fool with Windows Messaging garbage.

 

But, fwiw, your solution is fine for a simple game where you just want to check each frame if a key is being pressed or not.

Share this post


Link to post
Share on other sites

Why don't you use sfml instead?  It's perfect for 2d games, and it has abstracted out input, audio, windows, views, network, etc. already for you and you don't have to fool with Windows Messaging garbage.

 

But, fwiw, your solution is fine for a simple game where you just want to check each frame if a key is being pressed or not.

 

I have used sfml for a lot of things and I will keep using it cause I like it, but this project is just for 'fun' on how to learn how dx handles it on lower aspects.

 

I think about making a 2d platformer, where the user can have different skills to kill monsters and inventory and stuff like that. Just adding more and more till I am done with it I guess, maybe even multyplater if I feel like it. Is this sollution still fine then?

Share this post


Link to post
Share on other sites

Raw Input isn't really much more irritating than what you're doing already, but it will be kinder to you in the long run. You may want to check it out.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!