How to detect inputs with New Input System while game is unfocused?

Hello all,

I’m attempting to make a clicker/idle game that detects inputs while the player is doing other things on their computer, but I’m unable to figure out how to detect inputs while the game is unfocused.

I have an input action asset set up with the new input system to detect left mouse button clicks. It works fine when the game is focused, but (understandably) fails to detect clicks when the game is unfocused. This happens both in the editor and builds.

I have tried:

  1. Checking “Run in Background” in Player>Resolution and Presentation

  2. Choosing “Ignore Focus” in Input System Package>Background Behavior

  3. Playing in the editor and playing in a build

I’m using Unity 2020.3.28 and the new input system package version 1.3.0.

Just in case this helps, here’s my code for detecting mouse clicks with the new input system:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class InputManager : MonoBehaviour
{
    PlayerInputActions playerControls;
    InputAction mouseClick;

    private void Awake() {
        playerControls = new PlayerInputActions();
    }

    private void OnEnable() {
        mouseClick = playerControls.Player.MouseClick;
        mouseClick.performed += MouseClick;
        mouseClick.Enable();
    }

    private void OnDisable() {
        mouseClick.Disable();
    }

    private void MouseClick(InputAction.CallbackContext context) {
        Debug.Log("Mouse Click Detected!");
    }
}

Hello,
There are no such built-in functions in Unity and Csharp.
But you could use external libraries link that in this link:

Hope i could help you! And if this is not recommending for you, surly more people will write their idea here, maybe their answer is better.