SDL - Getting mouse input without events?

Started by
7 comments, last by Servant of the Lord 17 years, 6 months ago
I'm not particularily fond of event queues, and prefer to get input states as opposed to events. Actually, I'm using GetAsyncKeyState for my input, and so am completely dodging SDL events as much as I can, and only using SDL for graphics and(eventually) sound. Is there some way I can get the cordinates of the mouse without the event queue? I can get mouse clicks easily enough, but I'm not sure how to get the position. Perferably with a simple function, and I really don't care if it's a SDL function or not. Alternately, I can get the absalute corridates of the mouse from the topleft corner of the monitor's screen. If I can find out where my application window is, I can get the corridnates based off that. I can't find either of them on libSDL.(Either the app corridinates, or the mouse position w/o using events) Any help is greatly apreciated!
Advertisement
Try this...
SDL_GetMouseState()
Many thanks! That's exactly what I'm looking for.
If you like that you might also like:
SDL_GetKeyState()

-Artum.
Remember calling SDL_PumpEvents() in your main loop, if you're not doing any polling with SDL_PollEvent() or SDL_WaitEvent().
-- Rasmus Neckelmann
This is something which I do also, but if you use the mousewheel then you have to catch them via the event loop as there is currently no other way of getting the wheel movements :(
Thanks guys. Yeah I'm using SDL_PumpEvents and I have just switched out all my GetAsyncKeyState with SDL's SDL_GetKeyState (thanks Artum) as well, so as to have more crossplatformed code.

Luckily I haven't found a need for the mousewheel yet, so I haven't run across that hitch, AP, but thanks for the headsup!
Quote:Original post by Servant of the Lord
Thanks guys. Yeah I'm using SDL_PumpEvents and I have just switched out all my GetAsyncKeyState with SDL's SDL_GetKeyState (thanks Artum) as well, so as to have more crossplatformed code.

Luckily I haven't found a need for the mousewheel yet, so I haven't run across that hitch, AP, but thanks for the headsup!


You should still use PollEvent and grab SDL_Quit events, they can be generated in ways you dont expect. PollEvent calls PumpEvents internally, so you could replace the PumpEvents with a small poll-for-quit loop.

It wont affect your SDL_GetMouseState or SDL_GetKeyboardState either.
Quote:Original post by rip-off
You should still use PollEvent and grab SDL_Quit events, they can be generated in ways you dont expect. PollEvent calls PumpEvents internally, so you could replace the PumpEvents with a small poll-for-quit loop.

It wont affect your SDL_GetMouseState or SDL_GetKeyboardState either.


Thats a good idea. I'll add that later. I was wondering how I would allow people to hit [x] to close the window, without using PollEvent, but your way is good.

This topic is closed to new replies.

Advertisement