Making sure my XNA game has focus before handling mouse and keyboard events
Asked Answered
J

2

12

I'm developing a game that is mixed with winforms (for the map editor). The problem I am facing is that even if the main game window isn't in focus, it still receives mouse change events (such as clicking and moving the mouse).

Is there a way to make sure my application is in focus before continuing on to handle these events are is there some kind of built in method?

Thanks!

Jodijodie answered 3/3, 2012 at 23:5 Comment(0)
Z
18

Use the Game.IsActive property to check if you should deal with mouse and keyboard input.

Zaneta answered 3/3, 2012 at 23:21 Comment(0)
M
2

If you add a reference to System.Windows.Forms you can check if the XNA window is active like this:

if (System.Windows.Forms.Form.ActiveForm ==
    (System.Windows.Forms.Control.FromHandle(Window.Handle) as System.Windows.Forms.Form))
{
    // Active form is the XNA window.
}
Monique answered 3/3, 2012 at 23:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.