Keyevents

Do I need a screen to be open to use the key events?

If I just want a console program to read keys as they are pressed, how
do I do this in SDL? I have a program that reads the keys when I have a
screen open, however, the code didn’t seem to work when I tried without
the screen.

thanks

Henry Gomersall
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20021121/282e6a7f/attachment.pgp

Do I need a screen to be open to use the key events?

Yes.

If I just want a console program to read keys as they are pressed, how
do I do this in SDL? I have a program that reads the keys when I have a
screen open, however, the code didn’t seem to work when I tried without
the screen.

If you just want to read keyboard input from the console, you don’t
need SDL. Use the scanf/fscanf/getc functions instead:

while(1) {

char buffer[32];

printf ("Enter your name: ");
fflush (stdout);

scanf ("%s\n", buffer);

printf ("Your name is: %s\n", buffer);

}On Thursday, November 21, 2002, at 02:51 PM, Henry Gomersall wrote:

You don’t need a screen open, try something like…

SDL_Event *event

while(SDL_Pollevent(event)
{
switch(event->type)
{
case SDL_KEYDOWN:
switch(event->key->keysym)
{
case SDLK_a:
printLetter(‘A’); /* pretend function /
break;
case SDLK_b:
printLetter(‘B’);
break;
case SDLK_c:
printLetter(‘C’);
break;
case SDLK_q:
case SDLK_ESCAPE:
SDL_Quit();
exit(0);
break; /
just for looks /
case SDLK_F1:
doSomething(); /
not real */
break;
default:
break;
}
default:
break;
}
}

I wrote a program (and accidently compiled right over
the source key…damn my “itchy tab-key finger”) that
just tested for keyboard input and printed a response
with sdl.

more info can be found via the man pages and the
online documentation

Do I need a screen to be open to use the key events?

If I just want a console program to read keys as
they are pressed, how
do I do this in SDL? I have a program that reads the
keys when I have a
screen open, however, the code didn’t seem to work
when I tried withoutOn Thursday 21 November 2002 11:51 am, Henry Gomersall wrote:
the screen.

thanks

Henry Gomersall


Hello, I’m your mind.
Sorry I haven’t been around much,
but I’m easily distracted by shiny objects.
-The Tick’s Mind


Do you Yahoo!?
Yahoo! Mail Plus ? Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com