The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
How to get the initial mouse coords before moving the mouse?
Andre
Guest

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.

_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Faluk


Joined: 16 Apr 2015
Posts: 17
Hi Andre,

Do you have the event system initialized?

PS. Can't see anything attached.
How to get the initial mouse coords before moving the mouse?
Andre
Guest

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

Quote:
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.
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Faluk


Joined: 16 Apr 2015
Posts: 17
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.

Smile
How to get the initial mouse coords before moving the mouse?
Andre
Guest

Quote:
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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Re: How to get the initial mouse coords before moving the mo
Faluk


Joined: 16 Apr 2015
Posts: 17
Andre wrote:
Quote:
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

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
How to get the initial mouse coords before moving the mouse?
Andre
Guest

Quote:
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?
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Faluk


Joined: 16 Apr 2015
Posts: 17
I currently tested your code under windows 7. I will try it under linux during the weekend.
How to get the initial mouse coords before moving the mouse?
Andre
Guest

Thank you very much for your help so far.

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

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org