I've never actual asked a question on Stack Overflow, though just about every programming question I've ever had I found an answer here. Sadly today is not one of those days.
I've spent all day Googling, browsing the win32 api, and trying all sorts of things, but I just can't find the damn answer I'm looking for.
Here's the situation: I've got a Unity project I've created, it uses input from a joystick, there are other components to this project outside of unity, but that's irrelevant, the base of my problem is this: How can I make an application continue to accept input while it's out of focus/Inactive.
I know for a fact that it can be done because Borderlands 2 can do it (I found that out yesterday when I first started trying to find an answer, which was aggravating because that proves there is a way, and I'm failing to find it).
At the very least if someone knows how to do this for mouse or keyboard, that would be helpful enough to allow me to figure out how to apply it to a joystick.
Some helpful details: I'm an avid and experienced programmer, and I've been coding in: C/C++, C#, Java, and a number of scripting languages for many years. It is what I do as a hobby, for my job, in my spare time, while I'm asleep...
Things I've done / tried:
SetFocus
+ SetActive
from user32
& passing null
as the window
losing focusWM_KILLFOCUS
to the ignore list of the other window I want to read input while in backgroundsendmessage
to trick the other window into reading inputoverriding the inputstream
of the application (but this was useless sense I couldn't figure out how to send joystick input over
the stream, and also because It still didn't solve the problem sense
if that other application was out of focus (i.e. I open notepad),
input would stop.
I also searched for a way to make a Unity standalone game/project/application accept input while in background, but that yielded nothing.
I don't know if there is a Unity-related solution, but you can use the RawInput API to receive events directly from the Mouse/Joystick/HID hardware regardless of whether your app is in focus or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With