Not receiving input while focus lost

I’m trying to receive input while the game is not focused. I can’t get mouse or keyboard input working while the app is not focused. I’m making a utility for vtubers, so operating while other apps is focused is key.

I’ve tested with 1.1.1, 1.1.0-pre.6, and 1.0.2. I’ve tried polling and callbacks.

var mpos = ((Vector2)Mouse.current.position.ReadValue());
public InputActionReference MouseAction;
...
MouseAction.action.performed += (x) =>
{
    MousePos = x.ReadValue<Vector2>();
    Debug.Log(MousePos);
};

When looking at the input debugger, new mouse states are generating but the mouse values are not updating (this may be an editor only behavior). The events are not called. On Start() the Mouse shows that it supports running in background.

I’ve tried setting the Background Behavior setting to both “Reset And Disable Non Background Devices” and “Ignore Focus.”

The application is set to run in background. I’ve debugged to ensure that it is updating.

I’ve attempted setting the Update mode to Dynamic Update and also manually calling Update.

All of this is true for the Keyboard and Mouse.

Editor is set to “All Device Input Always Goes To Your Game View.”

The problem persists in builds.

I’ve put a lot of time into getting Input System working with my tool, but it’s starting to feel like I might have to jump to Rewired. Any advice on what to attempt next or any potential fixes? It feels like this is a bug in the Input System package.

EDIT: Clarified some verbiage.

I tried out 1.0.2. Still running into the problem. I made an example project and build. Hopefully I got all the settings the same as my main project. Here is the project (build is too large to attach).

Unity 2020.3.15f2

7579918–939484–Example Project.zip (1.26 MB)

I’ve started diving into the source code for the Input System and have not yet found any solutions. I will continue to try though. It would definitely seem that the problem lies in the Input System not in my use of it. I’m afraid it might be outside the scope of the open source portion of the Input System.

I’ve finished my migration to Rewired. I’m keeping the Input System branch alive in my project to hopefully help figure out what’s going on with this.

Just as a sanity check, have you made sure the InputAction is enabled?

Yup :c

Keyboard in background is unlikely to work, because then we will be a keylogger, which some OS don’t allow.

If you do this with Debug.Log in Update() of some MonoBehaviour, does it print correct values when the editor is not in focus?

var mpos = ((Vector2)Mouse.current.position.ReadValue());

If yes, problem is somewhere in InputAction layer, might be misconfiguration or edge case we missed

Any update on this?

I had to migrate my project to Rewired. Which was able to get me the input I needed while unfocused. I haven’t checked in on it since.