How to get the initial mouse coords before moving the mouse?

Hi everybody,

I have a problem with SDL_GetMouseState: I want to get the inital
mouse coords before the user moves the mouse, but the function only
returns 0 for the x and y coord.

I have attached a MWE that shows my problem. The first line that is
printed is always “init: 0, 0”. I expected it to give the actual coords.

I tried this example under Linux only.

I really appreciate any help you can provide.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: sdl_mouse.c
Type: text/x-csrc
Size: 788 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20161110/13c00070/attachment.c

Hi Andre,

Do you have the event system initialized?

PS. Can’t see anything attached.

Do you have the event system initialized?
Which function do you mean exactly? I called SDL_PumpEvents before
SDL_GetMouseState.

PS. Can’t see anything attached.
Mailman separated the attachment from my email. See
http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20161110/13c00070/attachment.c
for my attachment.

Hi Andre,

The problem is that if the mouse is outside the window there is no data to get. If the SDL_GetMouseState is called while the window is inside the window you will get data. Try creating a bigger where the mouse is inside the window.

:slight_smile:

The problem is that if the mouse is outside the window there is no data
to get. If the SDL_GetMouseState is called while the window is inside
the window you will get data. Try creating a bigger where the mouse is
inside the window.

I’m not talking about the case where the mouse is outside the program.

Run my attached program. Then remember the position of the window. Close
the program. Then move the mouse into the position where the window was
created last time. Start the program again.

Now you can see that the initial call of SDL_GetMouseState always
returns (0,0) although the mouse is inside the window.

Andre wrote:

The problem is that if the mouse is outside the window there is no data
to get. If the SDL_GetMouseState is called while the window is inside
the window you will get data. Try creating a bigger where the mouse is
inside the window.

I’m not talking about the case where the mouse is outside the program.

Run my attached program. Then remember the position of the window. Close
the program. Then move the mouse into the position where the window was
created last time. Start the program again.

Now you can see that the initial call of SDL_GetMouseState always
returns (0,0) although the mouse is inside the window.


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

Maybe is the library you are using. Your same code is is working perfectly for me:

Code:
init: 92, 120
move: 92, 120
move: 88, 114
move: 81, 103
move: 71, 89
move: 43, 52
move: 17, 23
move: 0, 0

Maybe is the library you are using. Your same code is is working perfectly for me:

Ok, then it’s a bug.

Can you please tell me what operating system + DE + window manager you
are using, so I can provide this information in the bug report?

I currently tested your code under windows 7. I will try it under linux during the weekend.

Thank you very much for your help so far.

I filed a bug under https://bugzilla.libsdl.org/show_bug.cgi?id=3487