Visual Studio 2013 keyboard blocks mouse input

Hello, I’m quite new to MonoGame and I faced a problem with it. I am trying to make a Windows 8.1 Universal App with MonoGame template, and noticed, that there’s a strange bug with mouse. On my PC everything works fine: I can type on keyboard&click the mouse at the same time. But on my laptop it is not. If i type, my touchpad is not detecting the click event. By the way, I can move the cursor, while I type, so no, it isn’t just blocking it. I listened to MouseState of this process, and noticed, that while I’m typing, there isn’t any “Pressed” event. Ony released. Again, this happen only on laptop, on PC code works perfectly. Can it be an issue with detecting a laptop touchpad? Oh, and some piece of code:

public void Update(GameTime gameTime)
        {
            mouseState = Mouse.GetState();
            keyboard = Keyboard.GetState();
            ico.Update(gameTime);
            ButtonIcon[] temp = {button1,button2,button3,button4 };
            for (int i = 0; i < temp.Length;i++)
                if (temp[i].ShowArea(ref mouseState, ref oldState, Vector2.Transform(mouseState.Position.ToVector2(), Matrix.Invert(screenXForm))))
                {
                    ClassicLevel_selectButton(i);
                }
            
            if (CheckKeyboard(Keys.Down) || CheckKeyboard(Keys.S))
            {
                frame++;
                if (frame > frameLimit)
                    frame = 2;
                selectionRect = new Rectangle(frame*65,0,65,65);
            }
            else if (CheckKeyboard(Keys.Up) || CheckKeyboard(Keys.W))
            {
                frame--;
                if (frame < 2)
                    frame = frameLimit;
                selectionRect = new Rectangle(frame * 65, 0, 65, 65);
            }
            prevKeyboard = keyboard;
            oldState = mouseState;
        }
    public bool CheckKeyboard(Keys key)
    {
        return (keyboard.IsKeyDown(key) && prevKeyboard.IsKeyUp(key));
    }
    public bool ShowArea(ref MouseState touch, ref MouseState oldState,Vector2 pos)
    {
        if (_location.Contains(pos))
        {

            frameLoc = new Rectangle(0, 0, 65, 65);
            return WasPressed(ref touch, ref oldState,pos);
        }
        else
            frameLoc = new Rectangle(65,0,65,65);
        return false;
    }
    public bool WasPressed(ref MouseState currentState, ref MouseState oldState, Vector2 vect)
    {
        if (_location.Contains(vect)&&currentState.LeftButton== ButtonState.Pressed&&oldState.LeftButton == ButtonState.Released)
        {
            return true;
        }
        else
            return false;
    }
    public bool WasPressed(ref KeyboardState key)
    {
        if (key.IsKeyDown(Keys.Enter))
            return true;
        else
            return false;
    }

I can confirm this issue. To reproduce:

Using Visual Studio Express 2012 or 2013, create a default MonoGame Windows Store Project.

Replace the code in Game1.cs with the code below (supposed to paint the screen Red while mouse button is pressed):

This works when run on Windows 8/8.1, but on Windows 10 (laptops) only detect clicks occasionally.

using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;

namespace MonoGameWindowsStoreProject13
{
///


/// This is the main type for your game.
///

public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;

    public Game1()
    {
        graphics = new GraphicsDeviceManager(this);
        Content.RootDirectory = "Content";
    }

    /// <summary>
    /// Allows the game to perform any initialization it needs to before starting to run.
    /// This is where it can query for any required services and load any non-graphic
    /// related content.  Calling base.Initialize will enumerate through any components
    /// and initialize them as well.
    /// </summary>
    protected override void Initialize()
    {
        // TODO: Add your initialization logic here

        Windows.UI.Core.CoreWindow _window = Windows.UI.Core.CoreWindow.GetForCurrentThread();
        _window.PointerPressed += OnPointerPressed;
        _window.PointerReleased += OnPointerReleased;

        base.Initialize();
    }

    /// <summary>
    /// LoadContent will be called once per game and is the place to load
    /// all of your content.
    /// </summary>
    protected override void LoadContent()
    {
        // Create a new SpriteBatch, which can be used to draw textures.
        spriteBatch = new SpriteBatch(GraphicsDevice);

        // TODO: use this.Content to load your game content here
    }

    /// <summary>
    /// UnloadContent will be called once per game and is the place to unload
    /// game-specific content.
    /// </summary>
    protected override void UnloadContent()
    {
        // TODO: Unload any non ContentManager content here
    }

    /// <summary>
    /// Allows the game to run logic such as updating the world,
    /// checking for collisions, gathering input, and playing audio.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Update(GameTime gameTime)
    {
        // TODO: Add your update logic here

        base.Update(gameTime);
    }

    /// <summary>
    /// This is called when the game should draw itself.
    /// </summary>
    /// <param name="gameTime">Provides a snapshot of timing values.</param>
    protected override void Draw(GameTime gameTime)
    {
        if (PointerButtonPressedLeft) GraphicsDevice.Clear(Color.Red);
        else GraphicsDevice.Clear(Color.CornflowerBlue);

        // TODO: Add your drawing code here

        base.Draw(gameTime);
    }

     bool PointerButtonPressedLeft = false;
     void OnPointerPressed(object sender, Windows.UI.Core.PointerEventArgs args)
     {
        Windows.UI.Input.PointerPointProperties props = args.CurrentPoint.Properties;
        if (props.IsLeftButtonPressed)
        {
           PointerButtonPressedLeft = true;
        }
     }
     void OnPointerReleased(object sender, Windows.UI.Core.PointerEventArgs args)
     {
        Windows.UI.Input.PointerPointProperties props = args.CurrentPoint.Properties;
        if (props.PointerUpdateKind == Windows.UI.Input.PointerUpdateKind.LeftButtonReleased)
        {
           PointerButtonPressedLeft = false;
        }
     }
}

}

Thanks a lot for this tip. Actually, i found a solution, but it’s a kinda problem of the laptops. In Win10, go to Settings->Devices->Mouse&Pointer and there, set sensor delay. This worked for me, maybe it will help someone in future

Thanks FallenAngel, nice finding!

But still this is a serious bug, also affecting keyboard press polling. Mouse and keyboard polling appears to fail even in a simple default Monogame project, on Windows 10 on any laptop I could try.

This is a serious problem because any Windows Store app out there, created with Monogame and Visual Studio 2012, 2013 (and perhaps 2015 targeting Win8) will fail for any user with a laptop running Windows 10.

What we would need is a fix we can implement programmatically in our apps, like a Monogame fix. Or does anyone know an alternate way to poll mouse buttons and key presses, different than the standard one shown in my sample code above?

Update: I realized this issue I encountered may not be the same reported by FallenAngel as the fix above doesn’t work for me and behavior is slightly different, so I have created a new thread here for clarity.

This also happens with a GL windows project on win 10.

Swapping to the SharpDX version fixes it.

Edit:
Specifically this is affecting Neoforce Controls, Click functionality

Does your finding applies to the example I posted above too? If so:

This also happens with a GL windows project on win 10

Do you mean the ‘Monogame OpenGL’ template? Or a standard Visual Studio template?

Swapping to the SharpDX version fixes it.

Not sure I understand. The ‘MonoGame Windows Store Project’ I tried in the example above seems to use SharpDX. Or are you referring to something used by MonoGame code internally?

Thanks for replying!

Neoforce controls is a UI library compiled for MonoGame.

To achieve this i compile Neoforce with the MonoGame framework that i am targeting.

So for the game its created using the MonoGame Windows GL template.

Neoforce is then compiled using the framework

The result is the click event stops working.

If I retarget the references to the windows SharpDX solution it works, with no code changes.

This seems to have started with the change to windows 10.

I will try the example when I get home

@FallenAngel With input being blocked, you should notice its only the TouchPad that will have the issue, this is actually a “Feature” of them to stop the user using the mouse pad and clicking on the screen while typing. (Think palm of the hand resting on the mousepad when pressing the space bar, it might decide that your clicking the mouse.)

@Vitrosaurus Regarding the example, I used a slightly different test for mine. But input seems to be fine. It just seems to not work anymore in the UI library, which is very strange, that it works in SharpDX, but not OpenGL.

Strange indeed. Especially because in my case it’s the MonoGame version that uses SharpDX that doesn’t work.

Just out of curiosity, do you see clicks being missed in the following game, when it runs on a Windows 10 (laptop, because everything works fine on a desktop PC with Windows 10):

http://apps.microsoft.com/windows/app/4ad90094-406f-438a-8888-3e27f79bc419

This game is supposed to being developed with MonoGame.

Thanks again for the followup!

Late reply.

I have tested Ragdoll Run, its controls seem laggy and sticky.

Tried both keyboard and mouse controls.

Both seem to get “stuck” on the down event, and it takes pressing the key again (sometimes more then once) to return to normal.

I will try to recover an older Win 8.1 Laptop and test that too.