Capture Mouse on Click?

I am using my own GUI system and I still have this little hickup, whenever the mouse moves outside the window when clicked (dragging a slider for example), the mouseup is not registered, as it happens outside the window.

In Windows you normally just call CaptureMouse/ReleaseMouse on a MouseDown/Up … how is the best way to solve this in MonoGame?

Must not be cross-platform for me. user32.dll the only way?

Check if mouse is outside the window. If so, release.

That’s not resulting in a desired behaviour

What I did now, is making my on “Capture Mouse” Flag for each control - MouseState will trigger globally anyway and I just save which control had the mouse down received - so whenever a mouse up is registered (globally) it’s dispatched to the control which “captured” the mouse down before (if there is any).

I believe this should be fixed with this PR: [DesktopGL] Improve mouse handling outside gamewindow by harry-cpp · Pull Request #7440 · MonoGame/MonoGame · GitHub

It should be part of the MonoGame 3.8.1.* release.

I originally reported this issue here: DesktopGL: Mouse state has inconsistencies when mouse leaves the window while a mouse button is pressed · Issue #7434 · MonoGame/MonoGame · GitHub

1 Like