Simple events question

Hi.

I was today mucking about with SDL_GetKeyState() and discovered that
it’d only work if you had a “while(SDL_PollEvent(&event));” line before
it. I’m not technically up on this but why is this the case?
If you remove this line no keys are picked up by GetKeyState(). I’m
assuming that the PollEvent does something with the event buffer and
refreshes the internal GetKeyState() buffer, but it’d be nice to know.

I’m new to this so sorry for the dumb question.

Cheers,

-Lea.

Hi.

I was today mucking about with SDL_GetKeyState() and discovered that
it’d only work if you had a “while(SDL_PollEvent(&event));” line before
it. I’m not technically up on this but why is this the case?
If you remove this line no keys are picked up by GetKeyState(). I’m
assuming that the PollEvent does something with the event buffer and
refreshes the internal GetKeyState() buffer, but it’d be nice to know.

This is actually a feature.
The original thought was that people could call SDL_PumpEvents() once
in their main event loop, and then query the current device state
without incurring additional overhead. It turns out that people
expect to get updated information each time they call the function
(which is reasonable)

So, I’m open to discussion on this. :slight_smile:

BTW, there is a patch to have SDL_Get* get the device state directly
from the X server, but it addresses some interesting architectural
questions which I am still thinking about, so I haven’t applied it
to the main SDL codebase.

I’m new to this so sorry for the dumb question.

It was a good question. :slight_smile:

-Sam Lantinga				(slouken at devolution.com)

Lead Programmer, Loki Entertainment Software–
“Any sufficiently advanced bug is indistinguishable from a feature”
– Rich Kulawiec