Mouse/keyboard input fails on laptops and XBox running Windows 10

Note I posted about this in another thread but I realized this issue may not be the same reported by the original poster there, so I’m creating a new thread here for clarity.

On Windows 10, Mouse clicks and key pressed are not detected (or frequently missed) for all Monogame apps targeting Windows 8.1 and compiled with Visual Studio 2012/2013 (not sure about VS 2015 yet).

If confirmed, it’s a serious problem because it affects all apps out there, that are working fine on Windows 8/8.1, but fail when the user upgrades to Windws 10 (I just confirmed this for this game http://apps.microsoft.com/windows/app/4ad90094-406f-438a-8888-3e27f79bc419 apparently made with Monogame).

Reproducing the issue is easy. Using Visual Studio Express 2012 or 2013, create a default ‘MonoGame Windows Store Project’ called ‘MonoGameWindowsStoreProject13’ (if you use a different name you will need to change namespace name accordingly, at line 4 in Game1.cs, see below)

Replace the entire code in Game1.cs with the code below (change ‘namespace’ name at line 4 to match your project name if necessary).

This example is supposed to paint the screen Red while mouse button is pressed).

On Windows 10 (laptops/XBox) it appears to only detect clicks occasionally or not at all. It works fine on Windows 8.1.

I’m using the latest Monogame SDK. I updated Visual Studio to the latest patches from Microsoft.

Can anyone confirm? I tried on various laptops running Windows 10. A friend confirmed the issue on his XBox.

Doeas anyone know a fix?

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;
        }
     }
}

}

Did you ever get a reply on this issue? I have seen this in a project I am working on and it is very annoying. I am running on a desktop with Windows 10 Anniversary Update. I have a Windows (not UWP) MonoGame project. In that project, mouse clicks and keyboard events are handled very sporadically. Sometimes they work, sometimes they don’t. I replaced my code with the code used by MonoGame.Extended just to test and it suffers from the same issue. What is frustrating is that sometimes clicks register fine and sometimes they fail to register at all unless I restart the application. For example, I have a menu system where I can click a button that displays another set of buttons. Sometimes I can open the menu and click any of the buttons fine. Other times it takes a few clicks to register. Yet other times it does not register ever until I restart the application. Everything is completely deterministic and there is no reason it should work sometimes and not others. I have seen this with keyboard input also. Sometimes a key press registers, sometimes not.

I have seen this issue in VS 2015 and now VS 2017. I am using the PCL libraries for MonoGame, which shouldn’t matter, but I note it just in case. Oh, and MonoGame 3.6, latest release.

I’ve never heard of this issue in Windows projects. Getting the raw input is not working? So when you click it doesn’t register?

That was fixed recently. It’s on the development branch.
http://www.monogame.net/downloads/

Wasn’t that just a UWP issue?

Thanks, I will give the latest dev build a try later this evening and see if that fixes what I am seeing.

I tried the development build tonight and that seems to have fixed the issue. However, I did notice the Escape key doesn’t seem to trigger a keyboard event on my machine. A little curious. Other keys seem to work fine. I will look into that one more before I conclude it’s MonoGame. I should mention I am using MonoGame.Extended. Haven’t had a chance to debug much yet, but the Escape key does not produce a KeyPress event.

Perhaps Esc is one of those keys that store apps can’t see.
Was that something that worked in 3.4/3.5?