From ESOUI Wiki
This function returns true if the game window is focused, or false otherwise. Minimizing the window, Alt+Tabbing out of the window, and pressing the Windows key to open the Start Menu all unfocus the game.
if DoesGameHaveFocus() then d("Ah, good. We have your attention.") else d("Hm, seems like you're doing something else...") end