How do I toggle a button and Bind code to it?

Discussion in 'C' started by Leon8046, Apr 6, 2009.

  1. Leon8046

    Leon8046 New Member

    Joined:
    Apr 6, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Hello! I apologize if this is the wrong forum :embarasse I was a little confused by the layout, sorry!

    I would like to know if someone could look at my code and hopefully suggest a solution. I have been trying to apply a keyboard movement system (Like W S A D) to my game for 2 days now and no success. It's a simple system (not the best either)...

    Code:
        if( GTH_CanMove()    &&    g_pApp->m_myCharacter->isAlive)
        {
            if( g_input->KeyEvent( DIK_NUMPAD8 ) )
            {
                g_pApp->m_myCharacter->event = GTH_EV_CHAR_MOUSERUN;
            }
            else if( g_input->KeyEvent( DIK_NUMPAD5 ) )
            {
                g_pApp->m_myCharacter->event = GTH_EV_CHAR_MOUSEWALK;
            }
            else if( g_input->KeyEvent( DIK_NUMPAD6 ) )
            {
                g_pApp->m_myCharacter->event = GTH_EV_CHAR_RUNRIGHT;
            }
            else if( g_input->KeyEvent( DIK_NUMPAD4 ) )
            {
                g_pApp->m_myCharacter->event = GTH_EV_CHAR_RUNLEFT;
            }
            else if( g_input->KeyEvent( DIK_NUMPAD3 ) )
            {
                g_pApp->m_myCharacter->event = GTH_EV_CHAR_WALKRIGHT;
            }
            else if( g_input->KeyEvent( DIK_NUMPAD1 ) )
            {
                g_pApp->m_myCharacter->event = GTH_EV_CHAR_WALKLEFT;
            }
            else
            {
            g_pApp->m_myCharacter->event = GTH_EV_CHAR_IDLE;
            }
    }
    This is how I have it at the moment, but if I am not moving that character is always IDLE, which unfortunately disabled point and click movement. My question is, Can I bind this code to a toggle key? say if I press F11 it will enable keyboard movement and disable mouse. If I press F11 again it will disable keyboard movement and enable mouse. Is this possible? or are there any other work arounds for this?

    Any help would be much appreciated. If you would like to look at the code in more detail then please do not hesitate to ask :nice: Thank you!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice