Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I alt-tab and do stuff outside of the game window, the game still captures mouse clicks (both left and right clicks).

The game doesn't "consume" the clicks, since they are also sent to the application that has the focus.

But it's rather annoying to hear a gunshot each time you click in your internet browser...

Also, the problem occurs even if the game is set to fullscreen.

share|improve this question
up vote 15 down vote accepted

The best solution I have found to this is to stop responding to input (and probably pause your game as well) if it goes inactive.

You can check Game.IsActive or hook the Activated and Deactivated events.

There is one minor drawback - I would just about consider this a bug in the framework - the game always starts in the Active state, even if the game isn't actually active when it starts running. (For example: you click to another window between launching your game and your game actually starting.)

You could work around this by checking what the active window is when your game starts, probably using GetForegroundWindow. Or you could just not worry about it - it occasionally happens as a developer, but I suspect it doesn't really affect end-users.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.