API reference / Application
SDL_AppEvent
Function, SDL3
You write this function. SDL calls it for each event, such as a key press or a click on the close button.
Declaration
#include <SDL3/SDL.h>
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event);Parameters
appstate | The pointer that you stored in SDL_AppInit. |
event | The event. |
Return value
SDL_APP_CONTINUE to keep running, or SDL_APP_SUCCESS or SDL_APP_FAILURE to end the program.
Example
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
}
return SDL_APP_CONTINUE;
}See this code run in Open a window. Download the full program (.zip)
In Read the keyboard
SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
{
if (event->type == SDL_EVENT_QUIT) {
return SDL_APP_SUCCESS;
}
if (event->type == SDL_EVENT_KEY_DOWN && !event->key.repeat &&
event->key.scancode == SDL_SCANCODE_SPACE) {
orange = !orange;
}
return SDL_APP_CONTINUE;
}See this code run in Read the keyboard. Download the full program (.zip)
Notes
- Your program must handle
SDL_EVENT_QUIT, or the close button does nothing.
In SDL2
SDL2 has no main callbacks. You call SDL_PollEvent in a loop.