I am having a bit of trouble with the arrow keys repeating when I don’t want them to. I have a keyboard function that is called during the game loop. It works as expected with the wasd keys which control directions. The problem is that when I use the arrow keys, which are expected to work the same, they repeat very quickly even though my condition is “if (e.type == SDL_KEYDOWN && e.key.repeat==0)”.
Somehow the arrow keys are still repeating even though the letter keys do not. I’m running on Ubuntu Linux but I don’t think that would make much of a difference. Is there something I missed?
void keyboard()
{
int key;
SDL_PollEvent( &e );
if( e.type == SDL_QUIT ){loop=0; printf("X clicked! This program will close!\n");}
if (e.type == SDL_KEYDOWN && e.key.repeat==0)
{
key=e.key.keysym.sym;
switch(key)
{
case SDLK_ESCAPE:
loop=0;
break;
case SDLK_z:
block_rotate_left_basic();
break;
case SDLK_x:
block_rotate_right_basic();
break;
case SDLK_c:
block_hold();
break;
/*the main 4 directions*/
case SDLK_KP_8:
case SDLK_UP:
case SDLK_w:
tetris_move_up();
break;
case SDLK_KP_2:
case SDLK_DOWN:
case SDLK_s:
tetris_move_down();
break;
case SDLK_KP_4:
case SDLK_LEFT:
case SDLK_a:
tetris_move_left();
break;
case SDLK_KP_6:
case SDLK_RIGHT:
case SDLK_d:
tetris_move_right();
break;
case SDLK_COMMA:
tetris_load_state();
break;
case SDLK_PERIOD:
tetris_save_state();
break;
}
}
}