• Advertisement
Sign in to follow this  

SDL Input Manager

This topic is 1619 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

Hy,

I worked on an Input manager but it doesnt work.

This is, what it looks like:
 

#include "cInput.h"


cInput::cInput(void)
{
    m_MouseX = 0;
    m_MouseY = 0;

    for(int i = 0; i < 323; i++)
    {
        m_keys[i] = false;
    }
}

void cInput::handleInput(SDL_Event evt)
{
    while(SDL_PollEvent(&evt))
    {
        switch(evt.type)
        {
        case SDL_QUIT:
            running = false;
            break;
        case SDL_KEYDOWN:
            m_keys[evt.key.keysym.sym] = true;
            //if i add if(evt.key.keysym.sym == SDLK_ESACPE) running = false; it works.
            break;
        case SDL_KEYUP:
            m_keys[evt.key.keysym.sym] = false;
            break;
        case SDL_MOUSEBUTTONDOWN:
            if(evt.button.button == SDL_BUTTON_LEFT)
            {
                m_leftMouse = true;
            }
            else
            {
                m_rightMouse = true;
            }
            m_MouseX = evt.button.x;
            m_MouseY = evt.button.y;
            break;
        case SDL_MOUSEBUTTONUP:
            if(evt.button.button == SDL_BUTTON_LEFT)
            {
                m_leftMouse = false;
            }
            else
            {
                m_rightMouse = false;
            }
            m_MouseX = evt.button.x;
            m_MouseY = evt.button.y;
            break;
        case SDL_MOUSEMOTION:
            m_MouseX = evt.button.x;
            m_MouseY = evt.button.y;
            break;
        }
    }
}


bool cInput::keyPressed(SDLKey key) // Here is the function
{
    return m_keys[key];
}

bool cInput::leftMousePressed()
{
    return m_leftMouse;
}


bool cInput::rightMousePressed()
{
    return m_rightMouse;
}


int cInput::getMousePositionX()
{
    return m_MouseX;
}


int cInput::getMousePositionY()
{
    return m_MouseY;
}

But now, when i try to use it in my main update function, it doesnt work. The Function "keyPressed" returns false every time.
 

if(Input->keyPressed(SDLK_ESCAPE))
{
    running = false;
}

 

Does anybody have an Idea what im doing wrong?

 

 

Share this post


Link to post
Share on other sites
Advertisement

This topic is 1619 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement