From d42f3e1a95c2021cbfdf885f21d87a7fa100f05a Mon Sep 17 00:00:00 2001 From: Andreas Oberritter Date: Thu, 31 Mar 2011 19:29:50 +0200 Subject: [PATCH] SDL: fix input of control keys --- lib/driver/rcsdl.cpp | 64 +++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/lib/driver/rcsdl.cpp b/lib/driver/rcsdl.cpp index 145b23ce..0705cb0f 100644 --- a/lib/driver/rcsdl.cpp +++ b/lib/driver/rcsdl.cpp @@ -1,3 +1,4 @@ +#include #include //#include #include @@ -18,6 +19,8 @@ eSDLInputDevice::~eSDLInputDevice() 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(); @@ -32,48 +35,43 @@ void eSDLInputDevice::handleCode(long arg) if (km == eRCInput::kmNone) { code = translateKey(key->sym); + D_PRINT("translated code: %d", code); } 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; + 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)); + D_RETURN(); } const char *eSDLInputDevice::getDescription() const -- 2.30.2