Key presses

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can get
input from the keyboard without it flipping out on me? Like, here’s how
I would update the current key being pressed:---------------------------------

bool keys[303];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
	keys[event.key.keysym.sym] = false;
	break;
}

}


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times. They keys are waay too
sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any way I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

  • Micah

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can get
input from the keyboard without it flipping out on me? Like, here’s how
I would update the current key being pressed:

A few things.


bool keys[303];

Where’d you get that ‘303’? Huh? Punk!? ;^)

You should be using:

bool keys[SDLK_LAST];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
keys[event.key.keysym.sym] = false;
break;
}
}

What’s outside of this block? Are you throttling how fast your
loop is being executed?


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times.

Did you happen to enable key repeat?

And are you certain it’s not just because of the fact that you
pushed the [Right] arrow down, then your loop iterated 20 times?

If so, your code is doing exactly what you want it to do. :^)

They keys are waay too sensitive.

I haven’t found this at all.

In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states.

I’d need to know what “readkey()” is/does to be able to speak to this.

Is there any way I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

Ah - So you’re not using SDL_Delay(). My guess is that your main loop
is iterating like mad. (That is, very very quickly :^) )

Your “if (keys[SDLK_RIGHT])…” block is getting executed a LOT between
the time you push the button and the time you release it.

Have you tried tapping the arrow key very briefly? You’ll probably
find that “x++” doesn’t happen quite as many times. :^)

You can do what I do, simply throttle your main loop to
"no more than N iterations per second" (e.g., 60fps), in which case
your “x++” would only happy 20 times if you held down the arrow key
for 2/3rds of a second. :^)

Or, you can do it the harder, more accurate way, and only
increment “x” a certain fraction of a whole number, based on the
FPS your getting on the particular computer you’re on.

All of your math (movement, collision detection, etc.) gets a lot harder,
though. :^( And depending on how much more crap you throw on the screen,
your FPS may drop, which means your math changes.

This FPS-related stuff has all been discussed before on the SDL list
(at least twice), so I’d check the archives. I’m sure it comes up on
other game programming lists, as well.

Good luck!

-bill!On Thu, Dec 12, 2002 at 06:42:24PM -0500, Micah Lee wrote:

Hi Bill,
May I know how’s your experience using Allegro ?----------------------------------------
Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Bill Kendrick [SMTP:nbs at sonic.net]
Sent: Friday, December 13, 2002 8:27 AM
To: sdl at libsdl.org
Subject: Re: [SDL] key presses

On Thu, Dec 12, 2002 at 06:42:24PM -0500, Micah Lee wrote:

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can get
input from the keyboard without it flipping out on me? Like, here’s how
I would update the current key being pressed:

A few things.


bool keys[303];

Where’d you get that ‘303’? Huh? Punk!? ;^)

You should be using:

bool keys[SDLK_LAST];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
  keys[event.key.keysym.sym] = false;
  break;
}

}

What’s outside of this block? Are you throttling how fast your
loop is being executed?


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times.

Did you happen to enable key repeat?

And are you certain it’s not just because of the fact that you
pushed the [Right] arrow down, then your loop iterated 20 times?

If so, your code is doing exactly what you want it to do. :^)

They keys are waay too sensitive.

I haven’t found this at all.

In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states.

I’d need to know what “readkey()” is/does to be able to speak to this.

Is there any way I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

Ah - So you’re not using SDL_Delay(). My guess is that your main loop
is iterating like mad. (That is, very very quickly :^) )

Your “if (keys[SDLK_RIGHT])…” block is getting executed a LOT between
the time you push the button and the time you release it.

Have you tried tapping the arrow key very briefly? You’ll probably
find that “x++” doesn’t happen quite as many times. :^)

You can do what I do, simply throttle your main loop to
"no more than N iterations per second" (e.g., 60fps), in which case
your “x++” would only happy 20 times if you held down the arrow key
for 2/3rds of a second. :^)

Or, you can do it the harder, more accurate way, and only
increment “x” a certain fraction of a whole number, based on the
FPS your getting on the particular computer you’re on.

All of your math (movement, collision detection, etc.) gets a lot harder,
though. :^( And depending on how much more crap you throw on the screen,
your FPS may drop, which means your math changes.

This FPS-related stuff has all been discussed before on the SDL list
(at least twice), so I’d check the archives. I’m sure it comes up on
other game programming lists, as well.

Good luck!

-bill!


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

I have none. I’ve used SDL for 4 years, though. :^)

-bill!On Fri, Dec 13, 2002 at 08:45:57AM +0800, Lai Kok Cheong wrote:

Hi Bill,
May I know how’s your experience using Allegro ?

But you did mention in your mail you have been using Allegro.Then later on
switch to SDL ?----------------------------------------
Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Bill Kendrick [SMTP:nbs at sonic.net]
Sent: Friday, December 13, 2002 8:53 AM
To: sdl at libsdl.org
Subject: Re: [SDL] key presses

On Fri, Dec 13, 2002 at 08:45:57AM +0800, Lai Kok Cheong wrote:

Hi Bill,
May I know how’s your experience using Allegro ?

I have none. I’ve used SDL for 4 years, though. :^)

-bill!


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

No. That wasn’t me. That was the person to whom I was responding. :^)
(Look at the “>” quoting carefully ;^) )

-bill!On Fri, Dec 13, 2002 at 09:06:16AM +0800, Lai Kok Cheong wrote:

But you did mention in your mail you have been using Allegro.Then later on
switch to SDL ?

Hi Micah,
May I know what was your experience on using Allegro ?----------------------------------------
Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Micah Lee [SMTP:micah at mindgrasp.com]
Sent: Friday, December 13, 2002 7:42 AM
To: sdl at libsdl.org
Subject: [SDL] key presses

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can get
input from the keyboard without it flipping out on me? Like, here’s how
I would update the current key being pressed:


bool keys[303];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
keys[event.key.keysym.sym] = false;
break;
}
}


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times. They keys are waay too
sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any way I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

  • Micah

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

Sorry Bill ;->----------------------------------------
Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Bill Kendrick [SMTP:nbs at sonic.net]
Sent: Friday, December 13, 2002 9:10 AM
To: sdl at libsdl.org
Subject: Re: [SDL] key presses

On Fri, Dec 13, 2002 at 09:06:16AM +0800, Lai Kok Cheong wrote:

But you did mention in your mail you have been using Allegro.Then later
on
switch to SDL ?

No. That wasn’t me. That was the person to whom I was responding. :^)
(Look at the “>” quoting carefully ;^) )

-bill!


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

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can get
input from the keyboard without it flipping out on me? Like, here’s how
I would update the current key being pressed:

I hate to say it, but this is a very “Allegro” way of doing things.
Storing keystrokes that are event driven off later so they can be polled.
There are SO many other better ways of doing so.

You didn’t mention what your code is doing, here. Are you wanting a
steady, consistent stream of activity when a key is held down, or are you
just wanting key repeat? If you want key repeat, just handle it in the
SDL_PollEvent() loop you create directly. Don’t store it off and check for
it later - do the activity right in the handling you have below:

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
keys[event.key.keysym.sym] = false;
break;
}
}


The only trouble is x gets ++ed like 20 times. They keys are waay too
sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any way I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

Without knowing if you want to just do normal key repeats or be notified
when a key is pressed (or released), it’s tough to answer your question.
Let me know, here, and I’ll do what I can to give you the best answer.

–>Neil-------------------------------------------------------------------------------
Neil Bradley In the land of the blind, the one eyed man is not
Synthcom Systems, Inc. king - he’s a prisoner.
ICQ #29402898

Hi Micah,
May I know what was your experience on using Allegro ?

You can know mine if you’d like. :wink: Consider it a DOS graphics library
ported to other environments. Lots of things, such as the "key array"
example already shown, and the “stop every once in a while and push sound
out the port” approach to audio, are throwovers from DOS days. SDL is not
hindered by such atrocities. :wink:

SDL Does a much better job all the way around. I’m curious why any non-DOS
developers even bother with Allegro any longer.

–>Neil-------------------------------------------------------------------------------
Neil Bradley In the land of the blind, the one eyed man is not
Synthcom Systems, Inc. king - he’s a prisoner.
ICQ #29402898

Ahh, I didn’t know there was an SDLK_LAST, or I would have used it. I
got 303 from looking in the header file- that was the last obvious one I
saw. Yes, I am throttling the loop. It’s locked at about 30fps. I
didn’t know about SDL_EnableKeyRepeat(), but it doesn’t seem to be doing
much. I have

SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY,
SDL_DEFAULT_REPEAT_INTERVAL);

in my init function, and I don’t notice a difference. If I change it to

SDL_EnableKeyRepeat(10000SDL_DEFAULT_REPEAT_DELAY,
10000
SDL_DEFAULT_REPEAT_INTERVAL);

it doesn’t seem to be any different. I checked it, and it does return 0
(which means it passed, -1 is failed). So I can just do all of my math
in fractions… but that would just suck. I guess I’ll go check the
archives. But if anyone can help me any more, please feel free.

  • Micah> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Bill Kendrick
Sent: Thursday, December 12, 2002 7:27 PM
To: sdl at libsdl.org
Subject: Re: [SDL] key presses

On Thu, Dec 12, 2002 at 06:42:24PM -0500, Micah Lee wrote:

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can
get
input from the keyboard without it flipping out on me? Like, here’s
how
I would update the current key being pressed:

A few things.


bool keys[303];

Where’d you get that ‘303’? Huh? Punk!? ;^)

You should be using:

bool keys[SDLK_LAST];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
  keys[event.key.keysym.sym] = false;
  break;
}

}

What’s outside of this block? Are you throttling how fast your
loop is being executed?


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times.

Did you happen to enable key repeat?

And are you certain it’s not just because of the fact that you
pushed the [Right] arrow down, then your loop iterated 20 times?

If so, your code is doing exactly what you want it to do. :^)

They keys are waay too sensitive.

I haven’t found this at all.

In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states.

I’d need to know what “readkey()” is/does to be able to speak to this.

Is there any way I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

Ah - So you’re not using SDL_Delay(). My guess is that your main loop
is iterating like mad. (That is, very very quickly :^) )

Your “if (keys[SDLK_RIGHT])…” block is getting executed a LOT between
the time you push the button and the time you release it.

Have you tried tapping the arrow key very briefly? You’ll probably
find that “x++” doesn’t happen quite as many times. :^)

You can do what I do, simply throttle your main loop to
"no more than N iterations per second" (e.g., 60fps), in which case
your “x++” would only happy 20 times if you held down the arrow key
for 2/3rds of a second. :^)

Or, you can do it the harder, more accurate way, and only
increment “x” a certain fraction of a whole number, based on the
FPS your getting on the particular computer you’re on.

All of your math (movement, collision detection, etc.) gets a lot
harder,
though. :^( And depending on how much more crap you throw on the
screen,
your FPS may drop, which means your math changes.

This FPS-related stuff has all been discussed before on the SDL list
(at least twice), so I’d check the archives. I’m sure it comes up on
other game programming lists, as well.

Good luck!

-bill!


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

I’ve used it for about a year or so, probably. I introduced it to my
high school computer science class, and started using it there a lot.
I’m fairly proficient at it- though I’ve never tried any of the 3D
functions.

  • Micah> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Lai Kok Cheong
Sent: Thursday, December 12, 2002 8:21 PM
To: sdl at libsdl.org
Subject: RE: [SDL] key presses

Hi Micah,
May I know what was your experience on using Allegro ?


Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Micah Lee [SMTP:@Micah_Lee]
Sent: Friday, December 13, 2002 7:42 AM
To: sdl at libsdl.org
Subject: [SDL] key presses

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can
get
input from the keyboard without it flipping out on me? Like, here’s
how
I would update the current key being pressed:


bool keys[303];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
  keys[event.key.keysym.sym] = false;
  break;
}

}


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times. They keys are waay too
sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any way
I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

  • Micah

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


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

i hear allegro has a software 3d engine, that is something that sounds
pretty valuable to me.> ----- Original Message -----

From: nb@synthcom.com (Neil Bradley)
To:
Sent: Thursday, December 12, 2002 5:49 PM
Subject: RE: [SDL] key presses

Hi Micah,
May I know what was your experience on using Allegro ?

You can know mine if you’d like. :wink: Consider it a DOS graphics library
ported to other environments. Lots of things, such as the "key array"
example already shown, and the “stop every once in a while and push sound
out the port” approach to audio, are throwovers from DOS days. SDL is not
hindered by such atrocities. :wink:

SDL Does a much better job all the way around. I’m curious why any non-DOS
developers even bother with Allegro any longer.

–>Neil



Neil Bradley In the land of the blind, the one eyed man is not
Synthcom Systems, Inc. king - he’s a prisoner.
ICQ #29402898


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

I’m programming Tetris as my first test program with SDL. So yeah, I
don’t want a steady stream of activity when a key is held down. The
reason I didn’t just do my activity right in the event loop is because
my activity changes based on the game state (well, not yet, but I’m
planning on it). Like, pressing left at the main menu won’t move any
Tetris pieces, but it will when you’re playing the game. I could just
check for the game state and handle all of the input for the entire
program at the SDL_KEYDOWN event, but I prefer to have input being
handled all over the place… like in my piece class’s update()
function. But I suppose I can do it this way if I have to. Isn’t there
a prettier way though?

And in response to your other post

SDL Does a much better job all the way around. I’m curious why any
non-DOS developers even bother with Allegro any longer.

That’s precisely why I’m switching to SDL… and that it looks a lot
better. Allegro in Windows isn’t always the stablest stuff I’ve seen.
And I someday plan on learning OpenGL- I’ve read good stuff about OpenGL
and SDL together.

  • Micah> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Neil Bradley
Sent: Thursday, December 12, 2002 8:39 PM
To: sdl at libsdl.org
Subject: Re: [SDL] key presses

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can
get
input from the keyboard without it flipping out on me? Like, here’s
how
I would update the current key being pressed:

I hate to say it, but this is a very “Allegro” way of doing things.
Storing keystrokes that are event driven off later so they can be
polled.
There are SO many other better ways of doing so.

You didn’t mention what your code is doing, here. Are you wanting a
steady, consistent stream of activity when a key is held down, or are
you
just wanting key repeat? If you want key repeat, just handle it in the
SDL_PollEvent() loop you create directly. Don’t store it off and check
for
it later - do the activity right in the handling you have below:

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
  keys[event.key.keysym.sym] = false;
  break;
}

}


The only trouble is x gets ++ed like 20 times. They keys are waay too
sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any way
I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

Without knowing if you want to just do normal key repeats or be notified
when a key is pressed (or released), it’s tough to answer your question.
Let me know, here, and I’ll do what I can to give you the best answer.

–>Neil



Neil Bradley In the land of the blind, the one eyed man is
not
Synthcom Systems, Inc. king - he’s a prisoner.
ICQ #29402898


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

So was it easy to use ? Was it fast ? Have you manage to create any game
on it ?----------------------------------------
Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Micah Lee [SMTP:micah at mindgrasp.com]
Sent: Friday, December 13, 2002 9:44 AM
To: sdl at libsdl.org
Subject: RE: [SDL] key presses

I’ve used it for about a year or so, probably. I introduced it to my
high school computer science class, and started using it there a lot.
I’m fairly proficient at it- though I’ve never tried any of the 3D
functions.

  • Micah

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Lai Kok Cheong
Sent: Thursday, December 12, 2002 8:21 PM
To: sdl at libsdl.org
Subject: RE: [SDL] key presses

Hi Micah,
May I know what was your experience on using Allegro ?


Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Micah Lee [SMTP:micah at mindgrasp.com]
Sent: Friday, December 13, 2002 7:42 AM
To: sdl at libsdl.org
Subject: [SDL] key presses

Hey, I just joined the list. This is my first post. I’ve been using
Allegro and I just decided to switch to SDL. Is there any way I can
get
input from the keyboard without it flipping out on me? Like, here’s
how
I would update the current key being pressed:


bool keys[303];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
  keys[event.key.keysym.sym] = false;
  break;
}

}


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times. They keys are waay too
sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any way
I
can make the keys not too crazy sensitive, but just about as sensitive
as they are in all other programs without using SDL_Delay()? Thanks.

  • Micah

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


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


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

Here’s what StepMania does: Each update, keep track of the current and
the last input state. If a key is on in this update but wasn’t in the
previous one, it’s the first press. If it’s on the the previous but not
this one, it was just released. Otherwise, it’s being held down.

Repeating is handled by keeping track of how long a key has been depressed
(this is layered above the input code). This means the keyboard repeat
rate and delay is up to your application, not the system; whether that’s
OK or not depends on the application.

(This isn’t SDL-centered; this code originally used DirectInput.)On Thu, Dec 12, 2002 at 08:51:46PM -0500, Micah Lee wrote:

I’m programming Tetris as my first test program with SDL. So yeah, I
don’t want a steady stream of activity when a key is held down. The
reason I didn’t just do my activity right in the event loop is because
my activity changes based on the game state (well, not yet, but I’m
planning on it). Like, pressing left at the main menu won’t move any
Tetris pieces, but it will when you’re playing the game. I could just
check for the game state and handle all of the input for the entire
program at the SDL_KEYDOWN event, but I prefer to have input being
handled all over the place… like in my piece class’s update()
function. But I suppose I can do it this way if I have to. Isn’t there
a prettier way though?


Glenn Maynard

It was very easy to use- like, a couple hundred times easier than
DirectX. It has functions for everything you can think of. You want a
circle? There’s a circle function. You want a filled in polygon?
There’s a filled in polygon function. You want a callback function to
be called with the coordinates passed to it that rotate around an
ellipse every 10 pixels? They’ve got that too. Timers are really easy
to use. They have a nifty datafile thing and a program called Grabber
that lets you take all your graphics, sounds, and even data files you
make yourself and load them into one file (which can be compressed and
password protected) and they can all be loaded with a simple
load_datafile() call.

Allegro is slow. I’ve never really made anything that takes too much
processing power, but it is very slow compared to DirectX and OpenGL
(and I think SDL, though I don’t have much experience with it).

I have made a couple of games with it, and started many, many, countless
more. I grew up learning game programming with Allegro. I made this
hardcore pong clone with powerups, and crappy vesions of tetris before I
was any good. I’ve made the snake game, and I even made up my own
little puzzle game called Blox. I even made this game called The
Sperminator where you’re a sperm swimming through the fallopian tube
avoiding the blobs of spermicide and collecting STDs for bonus points
until you get to the egg. Allegro is definitely a good library to start
learning with, but I don’t know about making anything professional or
anything you expect to sell with it.

  • Micah> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Lai Kok Cheong
Sent: Thursday, December 12, 2002 8:55 PM
To: sdl at libsdl.org
Subject: RE: [SDL] key presses

So was it easy to use ? Was it fast ? Have you manage to create any
game
on it ?


Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Micah Lee [SMTP:@Micah_Lee]
Sent: Friday, December 13, 2002 9:44 AM
To: sdl at libsdl.org
Subject: RE: [SDL] key presses

I’ve used it for about a year or so, probably. I introduced it to my
high school computer science class, and started using it there a lot.
I’m fairly proficient at it- though I’ve never tried any of the 3D
functions.

  • Micah

-----Original Message-----
From: sdl-admin at libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of
Lai Kok Cheong
Sent: Thursday, December 12, 2002 8:21 PM
To: sdl at libsdl.org
Subject: RE: [SDL] key presses

Hi Micah,
May I know what was your experience on using Allegro ?


Lai Kok Cheong
AIG Software International
G-1, Enterprise 1, Technology Park Malaysia
Bukit Jalil
57000, Kuala Lumpur
Malaysia
Tel: + 60 3 8996 0200
Fax: + 60 3 8996 0096
www.aigsi.com http://www.aigsi.com/

-----Original Message-----
From: Micah Lee [SMTP:@Micah_Lee]
Sent: Friday, December 13, 2002 7:42 AM
To: sdl at libsdl.org
Subject: [SDL] key presses

Hey, I just joined the list. This is my first post. I’ve been
using

Allegro and I just decided to switch to SDL. Is there any way I can
get
input from the keyboard without it flipping out on me? Like, here’s
how
I would update the current key being pressed:


bool keys[303];

if(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_KEYDOWN:
keys[event.key.keysym.sym] = true;
break;

case SDL_KEYUP:
  keys[event.key.keysym.sym] = false;
  break;
}

}


Then, later in my program, to see if the right arrow is pressed:


if(keys[SDLK_RIGHT])
{
x++;
}


The only trouble is x gets ++ed like 20 times. They keys are waay
too

sensitive. In Allegro I fixed this problem by using the readkey()
function instead of using their array of key states. Is there any
way
I

can make the keys not too crazy sensitive, but just about as
sensitive

as they are in all other programs without using SDL_Delay()?
Thanks.

  • Micah

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


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


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


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

I’m programming Tetris as my first test program with SDL. So yeah, I
don’t want a steady stream of activity when a key is held down. The
reason I didn’t just do my activity right in the event loop is because
my activity changes based on the game state (well, not yet, but I’m
planning on it). Like, pressing left at the main menu won’t move any
Tetris pieces, but it will when you’re playing the game. I could just
check for the game state and handle all of the input for the entire
program at the SDL_KEYDOWN event, but I prefer to have input being
handled all over the place… like in my piece class’s update()
function. But I suppose I can do it this way if I have to. Isn’t there
a prettier way though?

Depends upon what you mean by “prettier”. I’ll assume that means using an
object oriented approach, since that seems to be what you’re after.

When you get specific keys that you want, call each method that needs to
see it with an indication that a key is pressed or released. There’d be
nothing wrong with calling a menu() class and a gameframe() class. When
the menu is up, gameframe() ignores calls to it with key presses and frame
updates, but the menu() calls pay attention. And vice versa when a game is
playing. Also create a frame() method for each of your objects that’s
called each time a frame occurs. This will give you a consistent update
rate.

However, you mention that you prefer to “have input being handled all over
the place” - that’s about as anti-object oriented as it gets. Let each
object keep its own state on various key presses - or not. That’s up to
the object to decide.

So basically:

while (1)
{
render_game_frame();
sleep_until_next_frame();
examine_message_queue();
}

Now you’re checking for messages at a consistent time, and there’s no need
to keep track of every keypress.

SDL Does a much better job all the way around. I’m curious why any
non-DOS developers even bother with Allegro any longer.
That’s precisely why I’m switching to SDL… and that it looks a lot
better. Allegro in Windows isn’t always the stablest stuff I’ve seen.
And I someday plan on learning OpenGL- I’ve read good stuff about OpenGL
and SDL together.

You’ll find SDL to be more than adequate. I had a DirectX based video game
emulator (Retrocade) and I ported it to SDL so it’d run on more platforms.
The difference in performance between the two APIs is negligible.

–>Neil-------------------------------------------------------------------------------
Neil Bradley In the land of the blind, the one eyed man is not
Synthcom Systems, Inc. king - he’s a prisoner.
ICQ #29402898