Checking if a player tabbed out (no focus)?

Hi everybody,
I wanted to ask if there is a way to check if a player tabbed out the game / lost focus.
Hopefully someone has a solution for that.

I’m not entirely certain whether you can achieve what you’ve specifically requested, however the IsPauseMenuActive returns a bool depending on if the target player’s game is paused. It’s the closest native I could find right now which you could potentially utilise and make it work for your specific scenario.

Unfortunately, the function isn’t my solution, because I actually want to check whether the player is tabbed out or not. This function only returns the value 1, whenever the PauseMenu is opened.

@Lucky5 Do you mind if I ask you what you’re trying to achieve by attempting to check if a player is tabbed out?

I want to make it visible, if a player is currently tabbet out of the game. (Over the Head a text what says: Tabbed out). In some other APIs there is just a simple value (System::isFocused).

I think it’d be a better solution if you’d, say, just check for the last input time using GetTimeSinceLastInput - FiveM Natives @ Cfx.re Docs and use it being over 30 seconds ago or so as a marker of ‘yep, idle’ - some people may for example tab out but still be playing with e.g. a controller as gamepad input works fine if tabbed out in windowed mode, and showing those people as ‘tabbed out’ would be a bit silly, as you probably want to have it be an indicator of the user being idle. :stuck_out_tongue:

Similarly, a user can be idle without being ‘tabbed out’, so the specific kind of idle shouldn’t be relevant.

Either way, I think you can get if someone is tabbed out of a fullscreen game instance using IsInPowerSavingMode - FiveM Natives @ Cfx.re Docs, which has a bit of an illogical name.


In addition to the reasoning above, a general hint when trying to do something that doesn’t seem to have an obvious way to do so is to first find out why it is you want to do such.

In this case:

  1. You want to show if a user is tabbed out in an overhead display.
  2. As such, you would need to detect if a user is tabbed out.
  3. This doesn’t seem to be an option.

Asking from 3 would require people to first find out why (because you want to show it in an overhead display, and it’s easy in some other multiplayer scripting platform), but as that doesn’t really help find an answer here, one would have to imply further back from ‘1’ in your example.

However, if you then reason back again, for example (I don’t know if this is correct, I’m just guessing):

  1. You want users to be able to tell if someone around them isn’t looking at the game, for example so they will not expect a reaction back.
  2. This is something you can do by showing an overhead indicator.

… you’ll find out that there are multiple ways to tell someone isn’t actively engaging with the game, such as indeed if the player is just not using any inputs at all for a longer amount of time.

2 Likes