Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Captured mouse and WM_MOVE messages #396

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Captured mouse and WM_MOVE messages #396

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments


Copy link

@SDLBugzilla SDLBugzilla commented Feb 10, 2021

This bug report was migrated from our old Bugzilla tracker.

Reported in version: HG 2.0
Reported for operating system, platform: Windows (All), x86

Comments on the original bug report:

On 2011-03-22 08:19:42 +0000, Alex Denisov wrote:

In Windows OS, the file SDL_windowsevents.c converts WM_MOUSEMOVE event incorrectly:



SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam));

The issue is manifested in windowed mode, when the main window has captured the mouse using SetCapture() call from windows API. In this case, when the mouse is on the left or above the main window, WM_MOUSEMOVE is sending negative 16bit coordinates and LOWORD incorrectly typecasts it to an unsigned word. Typecasting LOWORD(lParam) to (Sint16)LOWORD(lParam) resolves the problem.

Of course, for this to work properly, further modifications are required in SDL_mouse.c. I had to remove the constraints on mouse cursor assignment:

if (mouse->x > x_max) { mouse->x = x_max; }, etc...

If would be nice if you could add a flag into the SDL_mouse structure to disable this check.

I know that in general, cursor capturing is not supported, but it would be beneficial for building GUIs based on SDL. At its present stage, it is possible to work around by using direct windows API calls, but some built-in support would be good.

On 2013-05-21 02:32:27 +0000, Sam Lantinga wrote:

Hey Jorgen, can you take a quick look at this for SDL 2.0 release?


On 2013-06-05 15:00:57 +0000, (disabled) Jørgen Tjernø wrote:

Alex, if you look at SDL_GetMouse()->last_x + event.motion.xrel and SDL_GetMouse()->last_y + event.motion.yrel, you should be able to get the coordinate outside the window even with SetCapture.

I'm updating the code so that it will properly cast the lParam, but I'm not adding any functionality (right now) to support mouse motion events with absolute values outside of the window.

Fixed in

Let me know if this works for you. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant