How to check if game window has focus?

I’d like to check it, because GD seems to take mouse input even when game window is not active. While it’s not important for setting in-game mouse cursor, shooting in my game is done using mouse click and you can accidentally lose level if you decide to check something in other application (ball will fall into blackhole and you’re done, level is restarted).