- Home /
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!");
}
}
Answer by gamynator · Feb 14 at 03:31 PM
Hello, There are no such built-in functions in Unity and Csharp. But you could use external libraries link that in this link: https://www.codeproject.com/Articles/7294/Processing-Global-Mouse-and-Keyboard-Hooks-in-C 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.
I'm hoping for another idea, but thank you for the information! This will be my last resort.
Your answer
![](https://koobas.hobune.stream/wayback/20220613052944im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
create default and customizable inputs 0 Answers
New Input System: Can't set binding path anymore 2 Answers
my input system dose not show up on the assets folder 0 Answers
Multiple Key Input for new Input System Limited? 1 Answer
what are the single joystick prefab's inputs for the input manager 1 Answer