MonoGame 3.7.0.1708: No Mouse Input Processed on Windows庐 10 UWP (XAML)

Created on 26 Sep 2018  路  17Comments  路  Source: MonoGame/MonoGame


After upgrading from MonoGame 3.6 to 3.7.0.1708, I detected that no mouse input is processed any more for the 'SwapChainPanel' UIElement (i.e. events like 'PointerMoved' do not get called any more unless the pointer is over a child UIElement). Even by explicitly using 'AddHandler' to attach a mouse handler to the swap chain panel and by setting the 'handledEventsToo = true' no input is processed.

What version of MonoGame does the bug occur on:

  • MonoGame 3.7.0.1708

What operating system are you using:

  • Windows 10 (17134.285)

What MonoGame platform are you using:

  • WindowsUWP + XAML
Windows 10 UWP

Most helpful comment

@AdrianWenz
The behavior was changed in https://github.com/MonoGame/MonoGame/pull/5520.
There were many reports of input lag and the way we address them was to run the input and the game-loop on two separate threads.

The CoreIndependentInputSource creates a 'shadow' windows with it's own message-pump and all input messages from SwapChainPanel are redirected there, that's why you are no longer able to see Pointer events from the SwapChainPanel.
I suppose you can do away with CoreIndependentInputSource since the main thread is no longer blocked by the CompositionTarget and you wont see any major lag.
I have modified InputEvents to act like 3.6 while you can enable the new behavior by setting a custom property at the CoreWindow.
Take a look: https://github.com/nkast/MonoGame/commit/9607b2265d1305ed9c3da64f255c37a0c017f499#diff-4275e55a3354530b36f6005576ef9845

All 17 comments

This works fine with an empty XAML template, therefore concluding that its not a bug on our side, closing...

Sorry @cra0zy, but your statement is incorrect.
Here is how to reproduce the issue:

  1. Create a project template 'MonoGame Windows 10 Universal (XAML) Project'
  2. Add a handler for 'PointerMoved' to the 'SwapChainPanel'
  3. Insert the handler code to the corresponding '*.cs' file.
    Unfortunately, pointer handlers are only called for buttons, sliders etc. but not for the swap chain panel itself. This behavior is different from MonoGame 3.6.

For your convenience I have attached a simple application with an empty XAML template.
MonoGame.zip

Add a handler for 'PointerMoved' to the 'SwapChainPanel'
Insert the handler code to the corresponding '*.cs' file.
Unfortunately, pointer handlers are only called for buttons, sliders etc. but not for the swap chain panel itself. This behavior is different from MonoGame 3.6.

I thought you were talking about MonoGames Mouse.GetState() stuff, this doesn't have to do anything with us I think.

@cra0zy
No, I was not talking about 'Mouse.GetState()'. Using this function might be a suitable way to process mouse input for a 'Desktop' application but not for a UWP XAML one.
The MonoGame framework should redirect the mouse input to the swap chain panel as well (not only to child UI Elements). The previous version 3.6. did implement this behavior correctly.

Please re-open this issue.
Thanks

Create a sample that demonstrates the issue with Mouse.GetState() returning an incorrect value.

@cra0zy Sorry, you don't get the point.
Just fire-up the supplied sample and you'll see that the handler for the swap chain panel is not called any more for MonoGame 3.7.0.1704. However, it does do that in MonoGame 3.6. This behavior is crucial for UWP XAML apps.

Again, please re-open this issue.
Thanks

SwapChainPanel is not a MonoGame control, its part of UWP: https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.controls.swapchainpanel

Again, your issue does not appear to have to do anything with MonoGame itself.

@cra0zy
MonoGame should not consume the mouse events for the swap chain panel control; as already stated, this is correctly implemented in the previous versions of MonoGame.
Using 'Mouse.GetState()' is very inconvenient for MonoGame UWP XAML applications.

If you do not understand this problem, then hand-on the issue to somebody else of the team.

Again, this issue has nothing to do with MonoGame:

  • Step 1: Create an empty UWP application, not MonoGame one, just a standard UWP application
  • Step 2: Add a SwapChainPanel element
  • Step 3: Connect PointerMoved event
  • Step 4: Notice that PointerMoved never gets called, and you have not used a single part that has anything to do with MonoGame :/

@cra0zy
I've attached a sample derived from the 'DirectX 11 and XAML App' UWP template demonstrating that the 'PointerMoved' handler is indeed called for the swap chain panel.
The only change other than adding the 'PointerMoved' handler to the template was to remove the non-UI thread handling the mouse, pen & touch i.e. pointer input.
It seems that the pointer input handling has changed in MonoGame 3.7.
TEST.zip

I am not even gonna bother going over that code, UWP probably has something like Gtk EventBox that it needs to process events, and either way, an empty non MonoGame UWP project demonstrates that the issue is not with MonoGame.

@AdrianWenz
The behavior was changed in https://github.com/MonoGame/MonoGame/pull/5520.
There were many reports of input lag and the way we address them was to run the input and the game-loop on two separate threads.

The CoreIndependentInputSource creates a 'shadow' windows with it's own message-pump and all input messages from SwapChainPanel are redirected there, that's why you are no longer able to see Pointer events from the SwapChainPanel.
I suppose you can do away with CoreIndependentInputSource since the main thread is no longer blocked by the CompositionTarget and you wont see any major lag.
I have modified InputEvents to act like 3.6 while you can enable the new behavior by setting a custom property at the CoreWindow.
Take a look: https://github.com/nkast/MonoGame/commit/9607b2265d1305ed9c3da64f255c37a0c017f499#diff-4275e55a3354530b36f6005576ef9845

@nkast
Thank you very much for the profound answer,
I'll try the code fix and send you a reply as soon as I have the time to do so.
Good job!

@nkast
Sorry, I need some more time before I can test your modifications. Expect it to happen around the beginning of next month (November).
As promised, I'll give you a note when done.
Thanks for your patience.

No problem. Note that in your case you might want to disable the Pen as well.

@nkast
As promised, I've tested your modifications as outlined at:
nkast@9607b22#diff-4275e55a3354530b36f6005576ef9845
I can confirm that MonoGame 3.7.0.1708 (including your code changes) now behaves like the previous version. However, I did not test the custom property to switch to an UI processing in a separate thread.

Thanks for your help.

Hello. I'm using MonoGame v3.7.1.189 with Universal XAML application.
How to receive PointerMoved event from SwapChainPanel? I need to get pointer pressure value.
When I create CoreIndependentInputSource then I can get point properties but no input is passed to game.
Or when I subscribe to swapChainPanel.PointerMoved then I never get any result. (my handler is never invoked).

How should I properly receive PointerMoved event and use device.GetState(..) in game?
Thanks for yours time and sorry for any bad grammar.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NET-D3v3l0p3r picture NET-D3v3l0p3r  路  3Comments

bjornenalfa picture bjornenalfa  路  5Comments

MichaelDePiazzi picture MichaelDePiazzi  路  4Comments

MichaelDePiazzi picture MichaelDePiazzi  路  4Comments

Legendree picture Legendree  路  3Comments