This is an old thread but still comes up when googling this topic
I think I have found the answer RE Blueprint
You can add the “Application Life Cycle” component to your object and that has delegates for Will Enter Background and Has Entered Foreground … which I think is what we are looking for in the case of
How to have a logic defined in a blueprint react to the app/game losing/gaining focus
Somewhat crazy this isn’t more clear you would think EVERY game needs to handle this at least on PC