Hi, i am trying to make a keystroke/click counter for a school project.
My problem is that when I start the program, it stops counting when I’m not focusing on it, so how do I make it able to listen to input while is on the background?
i already tried application.runinbackground = true and still does not work
Thank you so much for reading
In Player Settings “run in background” exists as an option. I don’t think think this differs from the API but this is guaranteed to work from the moment the app launches.
However, I don’t think you will receive input on a window that isn’t in the foreground. Just like applications don’t respond to keyboard input in general unless they are in the foreground.
There are ways to set up system-wide hotkeys but this requires a system-wide tool, something like AutoHotkey for instance. In Unity you’d probably have to make PInvoke calls to the Win32 API to set this up, and this may even require admin privileges.
It’ll be easier to learn how to script with AutoHotkey because that can definitely be a keystroke monitor. And then you could have that output the current number to a file and read that in Unity, or if available, any other means of direct process data exchange because file exchange isn’t as easy as it sounds due to permissions and that you can’t read while another app writes.
That made a lot of sense, yep i think i will give AutoHotKey a try and see where it goes, thank you so much for your response