Jump to content
  • Advertisement
Sign in to follow this  
Servant of the Lord

SDL - Getting mouse input without events?

This topic is 4408 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

Share this post


Link to post
Share on other sites
Advertisement
Remember calling SDL_PumpEvents() in your main loop, if you're not doing any polling with SDL_PollEvent() or SDL_WaitEvent().

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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 :(

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!