SDL Event & SDL_KEYDOWN

Started by
2 comments, last by Feralrath 16 years, 5 months ago
Hey. I'm wondering why whenever I produce a SDL_KEYDOWN event (in this case for example, the key m), the event_.motion.x equals 50?
SDL_Rect mouse = {event_.motion.x, event_.motion.y};
In my PollEvent loop, after I press the key m, ...motion.x is equal to 50 ALWAYS and ...motion.y is equal to 0 ALWAYS. Normally I wouldn't care but in this case pressing m displays the co-ordinates of the mouse for my program... Cheers.

Advertisement
Well, the values of event.motion are meaningless during a SDL_KEYDOWN event, only the event.key values have meaning.

Try waiting for SDL_MOUSEMOTION or SDL_MOUSEBUTTON, depending on what you want. If you are interested in the instantaneous mouse position, use SDL_GetMouseState().
So basically just store the values of the last valid mouse position while there are SDL_KEYDOWN events?

Cheers. :)

you can use SDL_MouseMotionEvent and pass the x and y positions by reference. then use the SDL_KeyDown event to active the display of the current mouse position, and have it display the values of the x and y that you passed to the mouse motion event.

This topic is closed to new replies.

Advertisement