Was looking for the same thing.
Usually input is pumped from the Messages Queues. Input (especially keyboard input) will only be placed in the queue of the focused application.
.microsoft.com/en-us/win…message-queues
To retrieve events if the application is not focused, you can register hooks.
.microsoft.com/en-us/win…ow%20procedure.
Though the hooks I was able to register did not work for me when the application was in the background.
Never the less I was looking for events from my XBox controller, and the hooks did not even catch those when the application was in the foreground.
When you use the RawInput plugin, you can fix it by copying the plugin to your project and changing the code:
RawInputWindows.cpp
FRawInputWindows::FRawInputWindows(const TSharedRef<FGenericApplicationMessageHandler>& InMessageHandler)
: IRawInput(InMessageHandler)
{
...
// Register a default device if desired
if (GetDefault<URawInputSettings>()->bRegisterDefaultDevice)
{
const uint32 Flags = RIDEV_INPUTSINK;//0; ** // CHANGE HERE**
const int32 PageID = 0x01;
int32 DeviceID = 0x04;
DefaultDeviceHandle = RegisterInputDevice(RIM_TYPEHID, Flags, DeviceID, PageID);
...
}
For the Flags, see here: .microsoft.com/en-us/win…rawinputdevice
When running the Editor:
The editor has performance throttels when in the background which can cause problems with the input even though the input should be queued by the system (?!?!).
1: One severe when the editor is minimized: hard throtteling to 3FPS.
To fix it you need to create a custom UUnrealEdEngine and register it in DefaultEngine.ini config file.
[/Script/Engine.Engine]
UnrealEdEngine=/Script/MODULENAME.CLASSNAMEWITHOUTPREFIX
Then in the custom UUnrealEdEngine override:
// We want the engine to always run full performance
virtual bool ShouldThrottleCPUUsage() const override
{
return false;
}
2: The second causes a 5ms sleep when in background and can only be fixed with a custom engine
WindowsPlatformApplicationMisc.cpp
Remove or change the code
FWindowsPlatformApplicationMisc::PumpMessages(bool bFromMainLoop)
{
...
#if WITH_EDITOR
if( HadFocus && !HasFocus )
{
// Drop our priority to speed up whatever is in the foreground.
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL );
}
else if( HasFocus && !HadFocus )
{
// Boost our priority back to above normal as initially set in WindowsRunnableThread::CreateInternal.
SetThreadPriority( GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL );
}
if( !HasFocus )
{
// Sleep for a bit to not eat up all CPU time.
FPlatformProcess::Sleep(0.005f);
}
HadFocus = HasFocus;
#endif
...
}