SDL: fix input of control keys
authorAndreas Oberritter <obi@opendreambox.org>
Thu, 31 Mar 2011 17:29:50 +0000 (19:29 +0200)
committerAndreas Oberritter <obi@opendreambox.org>
Thu, 31 Mar 2011 23:31:35 +0000 (01:31 +0200)
lib/driver/rcsdl.cpp

index 145b23c..0705cb0 100644 (file)
@@ -1,3 +1,4 @@
+#include <lib/base/etrace.h>
 #include <lib/driver/rcsdl.h>
 //#include <lib/actions/action.h>
 #include <lib/base/init.h>
 #include <lib/driver/rcsdl.h>
 //#include <lib/actions/action.h>
 #include <lib/base/init.h>
@@ -18,6 +19,8 @@ eSDLInputDevice::~eSDLInputDevice()
 
 void eSDLInputDevice::handleCode(long arg)
 {
 
 void eSDLInputDevice::handleCode(long arg)
 {
+       D_ENTER();
+
        const SDL_KeyboardEvent *event = (const SDL_KeyboardEvent *)arg;
        const SDL_keysym *key = &event->keysym;
        int km = input->getKeyboardMode();
        const SDL_KeyboardEvent *event = (const SDL_KeyboardEvent *)arg;
        const SDL_keysym *key = &event->keysym;
        int km = input->getKeyboardMode();
@@ -32,48 +35,43 @@ void eSDLInputDevice::handleCode(long arg)
 
        if (km == eRCInput::kmNone) {
                code = translateKey(key->sym);
 
        if (km == eRCInput::kmNone) {
                code = translateKey(key->sym);
+               D_PRINT("translated code: %d", code);
        } else {
        } else {
-               // ASCII keys should only generate key press events
-               if (flags == eRCKey::flagBreak)
-                       return;
-
-               eDebug("unicode=%04x scancode=%02x", m_unicode, key->scancode);
-               if (m_unicode & 0xff80) {
-                       eDebug("SDL: skipping unicode character");
-                       return;
-               }
-               code = m_unicode & ~0xff80;
-               // unicode not set...!? use key symbol
-               if (code == 0) {
-                       // keysym is ascii
-                       if (key->sym >= 128) {
-                               eDebug("SDL: cannot emulate ASCII");
-                               return;
-                       }
-                       eDebug("SDL: emulate ASCII");
+               code = m_unicode;
+               D_PRINT("native virtual code: %d / sym: %d", code, key->sym);
+               if ((code == 0) && (key->sym < 128)) {
                        code = key->sym;
                        code = key->sym;
+                       D_PRINT("ASCII code: %u", code);
                }
                }
-               if (km == eRCInput::kmAscii) {
-                       // skip ESC c or ESC '[' c
-                       if (m_escape) {
-                               if (code != '[')
-                                       m_escape = false;
-                               return;
-                       }
 
 
-                       if (code == SDLK_ESCAPE)
-                               m_escape = true;
+               if ((km == eRCInput::kmAscii) &&
+                   ((code < SDLK_SPACE) ||
+                    (code == 0x7e) ||
+                    (code == SDLK_DELETE) ||
+                    (code > 255))) {
+                       code = translateKey(key->sym);
+               } else {
+                       // ASCII keys should only generate key press events
+                       if (flags == eRCKey::flagBreak)
+                               D_RETURN();
 
 
-                       if ((code < SDLK_SPACE) ||
-                           (code == 0x7e) ||   // really?
-                           (code == SDLK_DELETE))
-                               return;
+                       if (km == eRCInput::kmAscii) {
+                               // skip ESC c or ESC '[' c
+                               if (m_escape) {
+                                       if (code != '[')
+                                               m_escape = false;
+                                       D_RETURN();
+                               }
+                               if (code == SDLK_ESCAPE)
+                                       m_escape = true;
+                       }
+                       flags |= eRCKey::flagAscii;
                }
                }
-               flags |= eRCKey::flagAscii;
        }
 
        }
 
-       eDebug("SDL code=%d flags=%d", code, flags);
+       D_PRINT("code=%d (%#x) flags=%d (%#x)", code, code, flags, flags);
        input->keyPressed(eRCKey(this, code, flags));
        input->keyPressed(eRCKey(this, code, flags));
+       D_RETURN();
 }
 
 const char *eSDLInputDevice::getDescription() const
 }
 
 const char *eSDLInputDevice::getDescription() const