From 61b7f6a8c2289ed8f3e6230a2553e08f1aa53380 Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Tue, 12 Jun 2018 20:23:32 +0200 Subject: [PATCH] improved code to handle special game controller buttons --- src/events.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/events.c b/src/events.c index c1a5cbc1..000744c9 100644 --- a/src/events.c +++ b/src/events.c @@ -2423,24 +2423,38 @@ void HandleJoystick() void HandleSpecialGameControllerButtons(Event *event) { #if defined(TARGET_SDL2) + int key_status; + Key key; + switch (event->type) { case SDL_CONTROLLERBUTTONDOWN: - if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START) - HandleKey(KSYM_space, KEY_PRESSED); - else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) - HandleKey(KSYM_Escape, KEY_PRESSED); - + key_status = KEY_PRESSED; break; case SDL_CONTROLLERBUTTONUP: - if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START) - HandleKey(KSYM_space, KEY_RELEASED); - else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK) - HandleKey(KSYM_Escape, KEY_RELEASED); + key_status = KEY_RELEASED; + break; + + default: + return; + } + switch (event->cbutton.button) + { + case SDL_CONTROLLER_BUTTON_START: + key = KSYM_space; + break; + + case SDL_CONTROLLER_BUTTON_BACK: + key = KSYM_Escape; break; + + default: + return; } + + HandleKey(key, key_status); #endif } -- 2.34.1