Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Roosh's avatar
Roosh
Honored Guest
8 years ago

ovrInput State: How to get button state correctly

I'm a native C# coder so my C++ is a little rusty. How can you check if a button was pressed in this frame and not just held down? Is there an event or something I can hook into instead of using a while statement? 
while (true)
{
ovrInputState inputState;
if (OVR_SUCCESS(ovr_GetInputState(session, ovrControllerType_Touch, &inputState)))
{
if (inputState.Buttons & ovrButton_Enter)
{
std::cout << "Pressed" << std::endl;
}
}
}

1 Reply

  • If you keep a copy of the input from the last frame, then:
    pressed = inputState.Buttons & ~lastState.Buttons;
    released = ~inputState.Buttons & lastState.Buttons;
    Then you can do things like
    if(pressed & ovrButton_Enter)
    to see if that button was pressed since the last frame.

    For triggers or thumbsticks, you can treat them as buttons with pressed or released checks like this:
    if(inputState.IndexTrigger[0]>0.5 && lastState.IndexTrigger[0]<=0.5)
    which checks if the left index trigger passed 50% press since the last update.