How To Use Global Inputs

Hi!

Normally, I develop games with Unity, but this time I wanted to create a mechanical keyboard sound application. I set everything up in the Editor, and it works perfectly fine as long as the Editor has focus.

I want to capture global keyboard presses when the application is out of focus so that I can play sounds when I hit the keys.

Yes, there are some open-source apps that do this, but I don’t feel very safe because of the keylogger risks.

I have tried hooks, but it lags a lot. Any other advice is appreciated.

Hi, you can turn on the “Run In Background” settings but only some devices support this, see
Input settings | Input System | 1.11.2.

In general, you can check in the Input Debugger whether a device supports running in background by checking if it set CanRunInBackground flag. This is also available via API. This Input Debugger, you can double click a device to see what flags it have set, see Debugging | Input System | 1.11.2.

For Keyboards specifically, this is typically not supported for security reasons (current application takes keyboard focus), but this may vary with OS and version. For Windows and macOS, keyboard “run in background” is not supported in Unity.

1 Like

Hi, thank you for the answer.

I wish there was a way to achieve this on Windows. But I totally understand the security reasons.