0

I'm using XInput for a project and I'm having a problem using the xbox controller. When I use the B button to return to a previous state, its registering the button press so fast that it continues to push back multiple states that use the B button to exit.

if( ( player1.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) || ( player2.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) ) {
    return ESC_BUTTON;
}

I've tried resetting the buffer by adding an & 1 but than the input never registers. Is there an easy way to fix this problem?

UPDATE:

current = (DWORD)( ( start - GetTickCount() ) / 1000.f );

if( current > 0.005f )
{
    if( ( player1.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) || ( player2.GetState().Gamepad.wButtons & XINPUT_GAMEPAD_B ) ) 
    {
        start = GetTickCount();

        return ESC_BUTTON;
    }
}

Still having issues with resetting. Sometimes it works, sometimes it doesn't...thoughts?

Josh Lake
  • 567
  • 1
  • 6
  • 17
  • Add a window where you record the last time it was pressed and if it is still depressed after that window accept that state again and process it. You can use something like half a second or a second so it's still responsive but won't handle the same press multiple times. – Jesus Ramos Apr 24 '13 at 22:20
  • That's one solution I was thinking of but I didn't know if I was overlooking something xinput did automatically. – Josh Lake Apr 24 '13 at 22:24
  • AFAIK this is the standard way. What I do is I have a bit array with the currently pressed things. If I want to process only on each press I wait for a press set the bit to 1, process the events and clear the bits for the processed ones. Both will get you the same results unless you want holding the button to also keep going back. – Jesus Ramos Apr 24 '13 at 22:26
  • Made a change yet still having issues – Josh Lake Apr 24 '13 at 23:01

0 Answers0