examples: Disable quitting with the escape key in Emscripten builds

This commit is contained in:
Cameron Cawley
2026-08-17 22:11:28 +01:00
committed by Sam Lantinga
parent 741668ab12
commit dca1503f00
3 changed files with 5 additions and 1 deletions

View File

@@ -214,10 +214,12 @@ void snake_step(SnakeContext *ctx)
static SDL_AppResult handle_key_event_(SnakeContext *ctx, SDL_Keycode key_code)
{
switch (key_code) {
#ifndef SDL_PLATFORM_EMSCRIPTEN
/* Quit. */
case SDLK_ESCAPE:
case SDLK_Q:
return SDL_APP_SUCCESS;
#endif
/* Restart the game as if the program was launched. */
case SDLK_R:
snake_initialize(ctx);

View File

@@ -434,7 +434,9 @@ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event)
case SDL_EVENT_KEY_UP: {
SDL_Scancode scancode = event->key.scancode;
SDL_KeyboardID id = event->key.which;
#ifndef SDL_PLATFORM_EMSCRIPTEN
if (scancode == SDL_SCANCODE_ESCAPE) return SDL_APP_SUCCESS;
#endif
int index = whoseKeyboard(id, players, player_count);
if (index >= 0) {
if (scancode == SDL_SCANCODE_W) players[index].wasd &= 30;

View File

@@ -346,7 +346,7 @@ SDL_AppResult SDL_AppEvent(void* appstate, SDL_Event* event) {
break;
case SDL_EVENT_KEY_DOWN:
#ifndef __EMSCRIPTEN__
#ifndef SDL_PLATFORM_EMSCRIPTEN
if (event->key.key == SDLK_ESCAPE) {
return SDL_APP_SUCCESS;
}