Skip to main content
New Participant
September 19, 2018

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

kojack
Honored Contributor
September 26, 2018
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.



Author: Oculus Monitor , Auto Oculus Touch , Forum Dark Mode , Phantom Touch Remover , X-Plane Fixer Hardware: Threadripper 1950x, MSI Gaming Trio 2080TI, Asrock X399 Taich Headsets: Wrap 1200VR, DK1, DK2, CV1, Rift-S, GearVR, Go, Quest, Quest 2, Reverb G2, Quest 3