Using mouse movement in SDL 1.2 even if cursor moves beyond window or screen

Hi,

As part of tuxmath, we now have an Asteroids-like game, and have added
mouse control of the ship. Specifically, the ship’s rotation is
controlled by lateral motion of the mouse. However, this only works
until the cursor hits the edge of the window or screen. The cursor
position itself isn’t used by the program. Does SDL provide a way to
receive all mouse-motion events, irrespective of the cursor position?
I can see that what I’m requesting might not make much sense if our
program is running in a window, but I would hope it would be supported
for fullscreen apps.

Thanks for any help,

David Bruce

You’ll need to set the mouse position to the center of the screen
every time you go through your main loop, that way you’ll continue to
receive motion events (as it will never hit the edge of the screen).On Thu, Dec 30, 2010 at 4:34 PM, David Bruce wrote:

Hi,

As part of tuxmath, we now have an Asteroids-like game, and have added
mouse control of the ship. ?Specifically, the ship’s rotation is
controlled by lateral motion of the mouse. ?However, this only works
until the cursor hits the edge of the window or screen. ?The cursor
position itself isn’t used by the program. ?Does SDL provide a way to
receive all mouse-motion events, irrespective of the cursor position?
I can see that what I’m requesting might not make much sense if our
program is running in a window, but I would hope it would be supported
for fullscreen apps.

Thanks for any help,

David Bruce


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Hi,On Thu, Dec 30, 2010 at 5:00 PM, Justin Coleman wrote:

You’ll need to set the mouse position to the center of the screen
every time you go through your main loop, that way you’ll continue to
receive motion events (as it will never hit the edge of the screen).

Well, looking through the docs, I found the following.

“If the cursor is hidden (SDL_ShowCursor(0)) and the input is grabbed
(SDL_WM_GrabInput(SDL_GRAB_ON)), then the mouse will give relative
motion events even when the cursor reaches the edge of the screen.
This is currently only implemented on Windows and Linux/Unix-alikes.”

So I guess I’m OK except for OS-X, in which case I can reposition the
mouse as you recommend. I take it that means using SDL_WarpMouse()?
The only problem seems to be that the repositioning itself generates a
mouse motion event every frame, which is making the control behave a
little erratically. Is there a clean, reliable way to ignore the
events generated by SDL_WarpMouse() without risking losing other
events? Alternatively, I could only do the reset-to-center when the
cursor hits the edge of the screen, rather than every frame, which at
most should cause an infrequent “hiccup”.

Thanks,

David Bruce