SDL_PollEvent confusion

Hi,

Please download http://www.laukamm.de/lars/debug/Void.rar (6KB) and run it. Requires SDL.dll and SDL_ttf.dll.

  1. Press TAB to open the console.
  2. Press and hold the ‘a’ key. Notice how it stops and then “lets loose” like a windows input box?
  3. Write a word slowly, with a certain delay between each letter. Should work fine.
  4. Now write a word as fast as you can. Notice the “bug”? (Too many occurances of the same letter)

The code is as follows:

bool *Input::Process()
{
SDL_PollEvent(&event);

i = event.key.keysym.sym;

if(event.type == SDL_KEYDOWN)
{

if(prevkeys[i] == false) // DONT BLOCK
{
 keys[i] = true;
 prevkeys[i] = true;   
}
else // BLOCK 
{
 if(fskipped[i] >= 6 ) // SKIP n FRAMES
  keys[i] = true;
 else
 {
  keys[i] = false;
  fskipped[i]++;
 }
}

}
else if(event.type == SDL_KEYUP)
{
keys[i] = false;
prevkeys[i] = false;
fskipped[i] = 0;

}

return keys;

}

I don’t see what the cause for the “bug” is. If anyone knows what’s going on, please let me know.

Thank in advance,

Regards,

-Lars

bool *Input::Process()
{
SDL_PollEvent(&event);

SDL_PollEvent() can return false. :slight_smile:
If it does, you shouldn’t execute the rest of the function.

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

Yes, I totally misunderstood the whole concept. The check for false as a
return value opened my eyes :wink:

Thanks,

-Lars> ----- Original Message -----

From: slouken@devolution.com (Sam Lantinga)
To:
Sent: Saturday, May 04, 2002 8:19 AM
Subject: Re: [SDL] SDL_PollEvent confusion …

bool *Input::Process()
{
SDL_PollEvent(&event);

SDL_PollEvent() can return false. :slight_smile:
If it does, you shouldn’t execute the rest of the function.

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


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