From c7f5d0a71d7318ccc4c3f28ab90d688a1a0868b3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 23 Aug 2013 18:03:05 +0300 Subject: fix keyboard handling in gui in SDL2. --- src/keyboardconfig.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/keyboardconfig.cpp') diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index d0c56ec1d..2bc33fc41 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -61,10 +61,14 @@ void KeyboardConfig::deinit() int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event) const { +#ifdef USE_SDL2 + return event.key.keysym.scancode; +#else if (event.key.keysym.sym) return event.key.keysym.sym; else if (event.key.keysym.scancode > 1) return -event.key.keysym.scancode; +#endif return 0; } @@ -84,7 +88,14 @@ std::string KeyboardConfig::getKeyName(const int key) if (key == Input::KEY_NO_VALUE) return ""; if (key >= 0) + { +#ifdef USE_SDL2 + return SDL_GetKeyName(SDL_GetKeyFromScancode( + static_cast(key))); +#else return SDL_GetKeyName(static_cast(key)); +#endif + } // TRANSLATORS: long key name, should be short return strprintf(_("key_%d"), key); @@ -138,7 +149,11 @@ std::string KeyboardConfig::getKeyShortString(const std::string &key) SDLKey KeyboardConfig::getKeyFromEvent(const SDL_Event &event) { +#ifdef USE_SDL2 + return event.key.keysym.scancode; +#else return event.key.keysym.sym; +#endif } KeysVector *KeyboardConfig::getActionVector(const SDL_Event &event) -- cgit v1.2.3-60-g2f50