diff --git a/android/src/main/java/SuperTuxKartActivity.java b/android/src/main/java/SuperTuxKartActivity.java index 32d74f075..92ada83f3 100644 --- a/android/src/main/java/SuperTuxKartActivity.java +++ b/android/src/main/java/SuperTuxKartActivity.java @@ -223,6 +223,7 @@ public class SuperTuxKartActivity extends NativeActivity int scan_code = event.getScanCode(); // KeyCharacterMap.COMBINING_ACCENT is not handled at the moment int unichar = event.getUnicodeChar(meta_state); + int repeat_count = event.getRepeatCount(); // Dispatch the different events depending on where they come from // Some SOURCE_JOYSTICK, SOURCE_DPAD or SOURCE_GAMEPAD are also SOURCE_KEYBOARD @@ -236,7 +237,7 @@ public class SuperTuxKartActivity extends NativeActivity // Note that we process events with specific key codes here if (action == KeyEvent.ACTION_DOWN) { - if (SDLControllerManager.onNativePadDown(device_id, key_code, meta_state, scan_code, unichar) == 0) + if (SDLControllerManager.onNativePadDown(device_id, key_code, meta_state, scan_code, unichar, repeat_count) == 0) return true; } else if (action == KeyEvent.ACTION_UP) @@ -246,7 +247,6 @@ public class SuperTuxKartActivity extends NativeActivity } } - int repeat_count = event.getRepeatCount(); // User pressed back button if (key_code == KeyEvent.KEYCODE_BACK && action == KeyEvent.ACTION_DOWN) diff --git a/src/input/sdl_controller.cpp b/src/input/sdl_controller.cpp index e3275e917..098067b60 100644 --- a/src/input/sdl_controller.cpp +++ b/src/input/sdl_controller.cpp @@ -208,4 +208,17 @@ void SDLController::handleAxisInputSense(const SDL_Event& event) m_prev_axes[axis_idx]); } // handleAxisInputSense +// ---------------------------------------------------------------------------- +#ifdef ANDROID +void SDLController::handleDirectScanCode(const SDL_Event& event) +{ + // Android STK has custom changes in SDL2 to allow gamepad with unknown + // button to use scan code directly + input_manager->dispatchInput(Input::IT_STICKBUTTON, + m_irr_event.JoystickEvent.Joystick, event.jbutton.button, + Input::AD_POSITIVE, + event.jbutton.state == SDL_PRESSED ? Input::MAX_VALUE : 0); +} // handleDirectScanCode +#endif + #endif diff --git a/src/input/sdl_controller.hpp b/src/input/sdl_controller.hpp index 8cd814fb7..114dd407c 100644 --- a/src/input/sdl_controller.hpp +++ b/src/input/sdl_controller.hpp @@ -46,6 +46,9 @@ private: irr::SEvent m_irr_event; int16_t m_prev_axes[irr::SEvent::SJoystickEvent::NUMBER_OF_AXES]; +#ifdef ANDROID + void handleDirectScanCode(const SDL_Event& event); +#endif public: // ------------------------------------------------------------------------ SDLController(int device_id); @@ -120,7 +123,12 @@ public: bool handleButton(const SDL_Event& event) { if (event.jbutton.button > m_buttons) + { +#ifdef ANDROID + handleDirectScanCode(event); +#endif return false; + } bool pressed = event.jbutton.state == SDL_PRESSED; uint32_t value = 1 << event.jbutton.button; if (pressed)