Hello!
I (and a couple of friends who tested my example) seem to have problems with SDL_EnableKeyRepeat in SDL 1.2.4.
The first time i use it my program it works fine, but the second time it makes no changes.
I hacked up a small test to show this…it is possible my code is broken, if so please tell me what Im doing wrong:
int
main(int argc, char *argv[])
{
SDL_Surface *screen;
SDL_Event event;
int quit=0, swap=0, check=0;
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO)<0) {
fprintf(stderr, "Could not initialize SDL: %s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen=SDL_SetVideoMode(320, 200, 8, SDL_HWSURFACE | SDL_DOUBLEBUF);
if(screen==NULL) {
fprintf(stderr, "Could not set video mode: %s\n", SDL_GetError());
exit(1);
}
while(quit!=1) {
if(swap==0) {
check=SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
if(check==-1) {
fprintf(stderr, "Could not set key repeat values: %s\n", SDL_GetError());
exit(1);
}
if(SDL_PollEvent(&event)) {
if(event.type==SDL_KEYDOWN) {
printf("key: %d\n", event.key.keysym.sym);
if(event.key.keysym.sym==SDLK_SPACE) {
printf("switching to faster key repeate\n");
swap=1;
}
else if(event.key.keysym.sym==SDLK_ESCAPE)
quit=1;
}
}
}
else {
check=SDL_EnableKeyRepeat(1, 1);
if(check==-1) {
fprintf(stderr, "Could not set key repeat values: %s\n", SDL_GetError());
exit(1);
}
if(SDL_PollEvent(&event)) {
if(event.type==SDL_KEYDOWN)
{
printf("key: %d\n", event.key.keysym.sym);
if(event.key.keysym.sym==SDLK_SPACE) {
printf("switching to default key repeat\n");
swap=0;
}
else if(event.key.keysym.sym==SDLK_ESCAPE)
quit=1;
}
}
}
}
exit(0);
}
switch mode with space and exit with esc.
it should make keys repeat very fast if you hold a key down when mode=1. This does not happen (where I’ve tried it).
Thanks
Sincerely,
Joel Carlbark
PS. Im not a member of the SDL list, so could you please cc to me?
PS2. If this issue is related to my crappy code or has been resolved in the current CVS, I appologize. Please tell me if that is the case though :)–
Get your free email from www.linuxmail.org
Powered by Outblaze