XNA – How to check if mouse or keyboard button has been clicked, pressed or released


I was reviewing some of the search terms that brought people to my website. It seems like a lot of them are related to using the mouse in XNA, so I figured I’d write a quick post about determining the mouse or keyboard state in XNA, though this applies to most anything that polls input and has a main loop.

Read the rest of this entry »

XNA – Check if a click is on the game form/window


One of the annoying things with XNA, happens when handling mouse clicks. If you’ve ever worked on an XNA windows game (note: this only really applies to a windows game) in windowed mode and tried switching applications, you may have noticed that XNA still captures the clicks even when the window is not active! It also reports the mouse position when it’s outside of the window which can cause more issues in and of itself. Unfortunately, the fix for the first problem doesn’t work if you’re using multiple forms in the same application.

So, we have three issues:

  • XNA captures clicks while the game is not active (i.e. from other applications)
  • and it reports the mouse position when it’s outside of the viewable area
  • and the fix for the first item above doesn’t work when you have multiple forms in your application.

Fortunately, there’s an easy way to resolve these! “Great!”, you say, “now how do I do it?”. Click on, my friend.

Read the rest of this entry »

Latest Posts



Post Calendar

August 2014
M T W T F S S
« Jun    
 123
45678910
11121314151617
18192021222324
25262728293031