0

I'm trying to design an app launcher system, and have figured out how to make the launcher run an app at path/app.exe, as well as attaching a listener to that process to detect when it has been closed.

Obviously, during this process, the launcher will lose focus as it moved into the background. Is there a way for it to continue to listen for keyboard input and perform an action in the background. It would be ideal if the launcher can then pass information to the running application, all without the application losing focus.

It is worth noting that both the launcher and the app will be made in Unity with c#, so if there is a solution that involved the app setting up some sort of listener for the launcher then that would be good, but for security reasons, the launcher must be the process that listens for the keyboard press action.

Vanguard3000
  • 223
  • 1
  • 6
  • 15
  • 1
    This is pretty old, you may have found your answer already but Unity has a setting to allow the game to run in the background instead of going idle. I would try that first. It is located under the presentation settings currently https://docs.unity3d.com/Manual/class-PlayerSettingsStandalone.html#Resolution – Jimmy Briggs Mar 14 '22 at 19:28
  • Thanks for letting me know! I honestly don't remember how I did it but it involved compiling as a dll. The project this was for ended up being scrapped for unrelated reasons (story of my life) but if I ever need to come back to it I'll keep your suggestion in mind. Thanks again! – Vanguard3000 Mar 16 '22 at 16:33

1 Answers1

1

There are some approaches to Interprocess Communication in the .NET Framework, of wich you can pick your Poison: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365574.aspx

It is also possible to intercept Keyboard events via low Level Keyboard hooks. However those require you use a unamanged Windows API. That in turn means, that you have left Managed Code: https://www.codeproject.com/Articles/19004/A-Simple-C-Global-Low-Level-Keyboard-Hook

The biggest uncertainty here is Unity. Usually Unity targets the Mono Framework. I am not sure wich IPC options Mono has. Also Unity is usually for programms that run on more then one OS (Linux/Windows/Mac compatibility). And that will limit your IPC options even more. And ruin your chances of getting Keyboard hooks going.

Christopher
  • 9,634
  • 2
  • 17
  • 31