Forum Discussion
Roosh
8 years agoHonored Guest
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 likeif(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.
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 9 years ago
- 7 months ago