Excluding keyboard events from event queue

hi all

i’m writing an application that displays some openGL stuff in an SDL
window, but still takes commands with gets() from the win32 console
(stdin). the openGL graphics need redrawing rather seldom, i.e. only
when a command is typed on the console. there is a problem about this:

if i draw to the window only once in a while, it will go into “program
doesn’t respond” state and clear itself which is rather ugly. i can
’wake it up’ again by polling all SDL events before doing a redraw but a
few seconds after redrawing it will go blank again.

so i should probably have the SDL event loop running all the time i
suppose. but then how can i read from stdinput? fgets() blocks until
something is entered, and the SDL event loop steals the console’s
keyboard events.

i really can’t think of a way to resolve this problems except switching
to the win32 API (shudder).

thx for any help
eik

so i should probably have the SDL event loop running all the time i
suppose. but then how can i read from stdinput? fgets() blocks until
something is entered, and the SDL event loop steals the console’s
keyboard events.

You might try creating a thread that reads from stdin and posts messages
to the SDL event queue to be handled by the main thread…

See ya!
-Sam Lantinga, Software Engineer, Blizzard Entertainment

so i should probably have the SDL event loop running all the time i
suppose. but then how can i read from stdinput? fgets() blocks until
something is entered, and the SDL event loop steals the console’s
keyboard events.

You might try creating a thread that reads from stdin and posts messages
to the SDL event queue to be handled by the main thread…

yes i thought of something similar, but let’s say i have the main thread
simply running an event poll loop, and a little thread just repeating
gets() and sending a message to the event queue aftwards…
but that wouldn’t stop the SDL event loop from stealing the keyboard
messages, would it? so my gets() would be getting nothing.
isn’t there a way of saying “i’m not interested, i won’t handle this
event” to certain events?

thx
eik

In fact, there is: SDL_EventState.

Does this, before the event loop, help?

SDL_EventState(SDL_KEYDOWN,SDL_DISABLE);
SDL_EventState(SDL_KEYUP,SDL_DISABLE);On Thursday 12 February 2004 05:29, Eike Umlauf wrote:

yes i thought of something similar, but let’s say i have the main thread
simply running an event poll loop, and a little thread just repeating
gets() and sending a message to the event queue aftwards…
but that wouldn’t stop the SDL event loop from stealing the keyboard
messages, would it? so my gets() would be getting nothing.
isn’t there a way of saying “i’m not interested, i won’t handle this
event” to certain events?

yes i thought of something similar, but let’s say i have the main thread
simply running an event poll loop, and a little thread just repeating
gets() and sending a message to the event queue aftwards…
but that wouldn’t stop the SDL event loop from stealing the keyboard
messages, would it? so my gets() would be getting nothing.

The keyboard messages SDL gets are those that go to the window SDL
is displaying. That’s why you have to set a video mode to get mouse
and keyboard input. SDL doesn’t intercept stdin at all.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Hello
i think i can help with this…

If you have a thread reading from stdin it will not overlay the event
loop becouse they are reading from diferent inputs.

Thats is, if your SDL window is focused, your key entry will go to the
event pool. If your console is focused your entry will go to the gets()
function.

I don’t knog how it’ll be if your using the FB backend, but in any
window system I think thil will be.

Anyway your stdin could be a file i you do
$ cat myfile > myprogram
in witch case your key pressings doesn’t matter in the console.

El jue, 12-02-2004 a las 08:29, Eike Umlauf escribi?:> >>so i should probably have the SDL event loop running all the time i

suppose. but then how can i read from stdinput? fgets() blocks until
something is entered, and the SDL event loop steals the console’s
keyboard events.

You might try creating a thread that reads from stdin and posts messages
to the SDL event queue to be handled by the main thread…

yes i thought of something similar, but let’s say i have the main thread
simply running an event poll loop, and a little thread just repeating
gets() and sending a message to the event queue aftwards…
but that wouldn’t stop the SDL event loop from stealing the keyboard
messages, would it? so my gets() would be getting nothing.
isn’t there a way of saying “i’m not interested, i won’t handle this
event” to certain events?

thx
eik


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl