I am trying to simulate an SDL keyboard button press (using C). I have looked up the SDL info pages online but I still don't have anything that consistently works.
I have the following (removed the interrupt handling, creation of windows etc.)
while(1){
SDL_Event user_event;
user_event.type = SDL_SCANCODE_LEFT;
SDL_PushEvent(&user_event);
SDL_PumpEvents();
const Uint8 *state = SDL_GetKeyboardState(NULL);
if (state[SDL_SCANCODE_LEFT]) {
printf("LEFT PRESSED");
}
if (state[SDL_SCANCODE_RIGHT]) {
printf("RIGHT PRESSED");
}
}
I never see the 'LEFT PRESSED' string printed out, although when I press the right arrow key (from keyboard) I see the respective output generated. It appears like the left key press is never being pushed on the state var.
Any help would be greatly appreciated.