Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm trying to add basic gamepad input to my c++ DirectX game but i'm having some trouble creating a press stamp (registers the press only the first time it's pressed if button held down).

The entire input class is here: https://gist.github.com/anonymous/28be899570c72fe7ae98

My ButtonPressed function:

bool Input::wasGamePadButtonPressed(int padNum, WORD button)
{
    if((gamepad[padNum].wButtons & button) & 
        ((gamepad[padNum].wButtons & button) != (prevGamepadState[padNum].wButtons & button)))
    {
        return true;
    }
    return false;
}

The It's just as basic press stamp, if the button is down, and the button was not down before, return true, else return false.

In my input::strobe() i strobe all the inputs and collect their states. at the beginning of the strobe i copy the current states and save them to a previous states structure

void Input::strobe(void)
{
    //hold on to the previous states for input stamping
    memcpy(prevKeys, keys, sizeof(keys));
    memcpy(prevGamepadState, gamepad, sizeof(gamepad));

    //gather keyboard
    HRESULT err;
    err = keyboard->GetDeviceState(sizeof(keys), (LPVOID) &keys);
    if((err == DIERR_INPUTLOST )|| (err == DIERR_NOTACQUIRED))
    {
        keyboard->Acquire();
    }

    //gather mouse
    err = mouse->GetDeviceState(sizeof(mouse_state), (LPVOID) &mouse_state);
    if((err == DIERR_INPUTLOST )|| (err == DIERR_NOTACQUIRED))
    {
        mouse->Acquire();
    }

    //strobe controllers
    if(hasGamepads)
    {
        for(int ii = 0; ii < 4; ii++)
        {
            ZeroMemory(&gamepad[ii], sizeof(XINPUT_STATE));
            XINPUT_STATE state;
            DWORD result = XInputGetState(ii, &state);

            if(result == 0)
            {
                gamepad[ii] = state.Gamepad;
            }
        }
    }
}

This works fine for my keyboard press stamp, which is very similar to the gamepad press function, but the game pad one refuses to work for some reason, firing true every frame for as long as i hold down the button.

It seems really straight forward so i cannot think of why it't not working. the only thing i can think is an issue in the strober, which i did not write originally (most of the basic directinput stuff was given in a class i took), or its me misunderstanding bitwise masks and I've got that gamepadpressed function totally wrong.

share|improve this question
    
What values can "button" have, specifically? –  Trevor Powell May 11 '13 at 0:59
    
these in the XINPUT_GAMEPAD structure: msdn.microsoft.com/en-us/library/… they're bitmasks –  Charles May 11 '13 at 1:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.