cancel
Showing results for 
Search instead for 
Did you mean: 

Mouse and Keyboard input

AndyBorrell
Protege
tl;dr You can't rely on your Rift game having keyboard and mouse focus. Also, ignore gamepad input when you don't have VR focus.

Rift users have a couple of different ways to start a Rift game: through the desktop client, or from Oculus Home in VR using a gamepad. The thing about this second method, by launching a game without using keyboard and mouse, is that your game might not have focus on the desktop.

This means that your game needs to be fully usable just using gamepad/Oculus Remote/Touch input - which you will always have access to regardless of which window has focus. This is good practice in any case since trying to find a mouse and keyboard while wearing a headset is a suboptimal experience.

For text input we would encourage you to use an in-VR virtual keyboard, most people who can't touch type will find this much easier to use than blind typing on a physical keyboard. If you feel that you absolutely 100% can't live without keyboard and mouse focus then asking the user to alt-tab into your window will work. This should rarely be necessary. If you have some use case which you think can't be solved with a virtual keyboard then please let us know.


The other half of this story is that since you can always get gamepad input, you need to careful that you ignore it when the headset is showing the Oculus Universal menu (after pressing the XBox button). The player will be pressing gamepad buttons to interact with the UM so make sure those button presses don't also do things in your game. You can tell when your game has VR focus by looking at the ovrSessionStatus.IsVisible flag. With our current custom Unity build you don't need to worry about ignoring this input since your game is automatically paused when the UM is visible. But stay tuned because we will be adding a way for multiplayer games to prevent this auto-pause behaviour, and in this case you would need to explicitly ignore input.
14 REPLIES 14

Anticleric
Expert Protege
This might effect me in a weird way.

I have 3rd person sections where you can aim with your head, but it's using mouse position. If I have focus, I grab the mouse and lock it to screen center.. but if it doesn't have focus.. the cursor is where the mouse is sitting.

Just need the player to click onto the game.. but there has to be a way to force this no?

AndyBorrell
Protege
I'm confused. If you aim with your head why do you need mouse focus?

econty
Explorer
"andyborrel" wrote:
I'm confused. If you aim with your head why do you need mouse focus?


My case is similar to Anticleric's. Currently, I'm using UE4, and I want to be able to navigate buttons in an UMG using the HMD to look-aim. Unfortunately, I couldn't find a way to get the WidgetComponent to tell me which button is currently being looked at, only that the WidgetComponent containing the entire UMG has focus.

So I worked around the problem by capturing the mouse forcing it to the center of the viewport, right where the cursor is. Then it's just a matter of checking IsHovered().

[Edited] Specified I'm on Unreal Engine 4.

Anticleric
Expert Protege
"econty" wrote:


So I worked around the problem by capturing the mouse forcing it to the center of the viewport, right where the cursor is. Then it's just a matter of checking IsHovered().

[Edited] Specified I'm on Unreal Engine 4.


This.. except with unity.

AndyBorrell
Protege
In Unity it's possible to drive the whole UI system off gaze direction instead of mouse input. This blog post goes into detail (and has reusable components) : https://developer.oculus.com/blog/unity ... tem-in-vr/

Something similar ought to be possible in UE4.

sh0v0r
Protege
"andyborrel" wrote:
In Unity it's possible to drive the whole UI system off gaze direction instead of mouse input. This blog post goes into detail (and has reusable components) : https://developer.oculus.com/blog/unity ... tem-in-vr/

Something similar ought to be possible in UE4.


This is what I am doing for Lunar Flight, one issue I have with the blogs implementation is the it uses 'OnClick' which means you have to release the button and this feels bad in general (IMO).

When I look at buttons in the cockpit and press the button I expect an immediate reaction 'OnDown' rather than 'OnUp'

Using OnUp means that if you start the press while looking at the button and your gaze moves off the button slightly the input focus is lost making it feel clunky. This is the same behaviour as when touch a button on mobile device and drag your finger off it.

For Physics Objects you can use the PointerDown Event Trigger but I haven't worked out what to change for UI Button events?

Edit:

OK I worked out how to make it work on the Pressed state, I just assigned the same input to both the pressed and released state in:

protected PointerEventData.FramePressState GetGazeButtonState()

Works like a charm and feels nice and snappy now!

Anticleric
Expert Protege
"andyborrel" wrote:
In Unity it's possible to drive the whole UI system off gaze direction instead of mouse input. This blog post goes into detail (and has reusable components) : https://developer.oculus.com/blog/unity ... tem-in-vr/

Something similar ought to be possible in UE4.


Hey Andy, in my case, it's not UI. You're controlling a 3D cursor to target enemies. Of course it is possible to have set this up with gaze direction.. but that's not the way I built it and we've only got a few weeks left..
Thise sections of my game are really messed up right now. I need to put down the gamepad, find the mouse and try to find screen center.

There has to be a way to lock the mouse center screen. If the best practice is to not use mouse input.. then shouldn't the default mouse position be center locked anyway? Otherwise someone can click off of the app on to another display.

Anticleric
Expert Protege
https://www.assetstore.unity3d.com/en/#!/content/17177

Would this get around the problem in Unity? I don't have time now, but I can try it as a last ditch effort to simply lock the mouse center screen.

Anticleric
Expert Protege
So.. seriously.. about this mouse thing. I'm going to try this asset. But like I said. Locking the mouse center isn't too much to ask I don't think.