GetMouseState sometimes returning wrong state

I’m just starting to track this but it seems like there is a bug with reading input from the mouse using:

var state = Microsoft.Xna.Framework.Input.Mouse.GetState();

This code works great, but as soon as I type a key on the keyboard, this function seems to return incorrect values. Specifically sometimes I’ll press the left mouse button and the LeftButton will return not pressed. Similarly, sometimes the left mouse button will be physically pushed and released, and the state will still return it as pressed (as if it’s stuck down).

The important thing to note is that everything works perfectly until I type something on the keyboard.

Other clues: if the mouse is moving then the buttons will return correct values, but if the mouse is standing still then it’s far more likely that the LeftButton property will report incorrect values. If the left button is reported as down when it really isn’t I can move the mouse and the correct LeftButton value will be returned.

Has anyone else seen this, or is anyone familiar enough with the code to provide some hints as to what might be going on?

I built against source (latest on “develop” branch) and this no longer seems to be a problem. Looks like it has been fixed at some point between 3.2 and the current version of the code.

Edit: Building against source seemed to make it happen less often but not 100% fixed. I’ll dig further…

Not sure my issue needs a new thread… but I’m getting very weird resulting using the Mouse.GetState() as well.

I have two projects, both with Input classes that have methods that return a MouseState:

public MouseState MouseFire()
    return Mouse.GetState();

Then, in my Update() I have:

    Input _i = new Input(); //my input class...
    var mouseFire = _i.MouseFire();
    if (mouseFire.LeftButton == ButtonState.Pressed)
        //do stuff and things

What’s weird, is that in my first project, everything works fine and as intended… Then, in the second project (using the same syntax) my mouse input don’t work at all and always returns null. I’ve tried different mice, etc nothing is working. Do you think using the 3.2 Release version is the problem?

Okay, so I figured out the bug; however, I’m not sure why it’s producing these results. Could someone help me figure this out?

I have 3 classes. Game1, Bullets, and Input; where, Bullets : Game1

My input class accepted WASD to move a ships position on the screen and LeftAlt fired some bullets. Here’s my Update():

protected override void Update(GameTime gameTime)
    if (Keyboard.GetState().IsKeyDown(Keys.Escape) == true)

    Input _i = new Input();
    //get player coordinates
    //get mouseState
    if (mouseFire.LeftButton == ButtonState.Pressed || _i.PlayerFire() == true)  
       //add new bullet to list based on player position
    //foreach bullet, update new coordinates.
    //remove bullets where collision and outOfBounds == true

My problem was that the Keyboard input would be returned for each frame correctly; while the Mouse input would always return False or a null. As soon as I removed the : Game1 inheritance from my Bullets class, both the keyboard and mouse work when pressed and stop shooting when released. Why does inheriting this class screw everything up for the mouse?

I did spend a little more time on this problem and ultimately MonoGame was not the cause of the problem - at least directly. I was building and running against source and I found out that the events that occurred when clicking would not always get fired. In fact, it seemed to drop a good portion of my events including clicking as well as movement. If I was moving the moue around then there would be a good chance that things worked correctly because movement essentially happened every frame. However, if clicks happened to occur during the period of dropped events then the click would never register.