Skip to main content
GameDev.net gamedev.net
🔒 Locked

Handle input

Started by NLScotty Mar 21, 2016 at 6:46 PM 2 replies 1.5k views
Original Post
NLScotty
NLScotty

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

BeerNutts
BeerNutts

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.

My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)
NLScotty
NLScotty

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?

Khatharr
Khatharr

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.

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.