From 6efb223b494118ead4475aa09b8105f133c58ef0 Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Sun, 3 May 2015 15:52:12 +0200 Subject: [PATCH 1/2] Fixing SDL char input. --- examples/common/entry/entry_sdl.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/examples/common/entry/entry_sdl.cpp b/examples/common/entry/entry_sdl.cpp index 6329bef9..28ef5f01 100644 --- a/examples/common/entry/entry_sdl.cpp +++ b/examples/common/entry/entry_sdl.cpp @@ -450,22 +450,7 @@ namespace entry { uint8_t modifiers = translateKeyModifiers(kev.keysym.mod); Key::Enum key = translateKey(kev.keysym.scancode); - - const uint8_t shiftMask = Modifier::LeftShift|Modifier::RightShift; - const bool nonShiftModifiers = (0 != (modifiers&(~shiftMask) ) ); - const bool isCharPressed = (Key::Key0 <= key && key <= Key::KeyZ) || (Key::Esc <= key && key <= Key::Minus); - const bool isText = isCharPressed && !nonShiftModifiers; - - if (isText) - { - uint8_t pressedChar[4]; - pressedChar[0] = keyToAscii(key, modifiers); - m_eventQueue.postCharEvent(handle, 1, pressedChar); - } - else - { - m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED); - } + m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED); } } break; From d21c75c40c68effc8c166c2d6c853ca75ab34fba Mon Sep 17 00:00:00 2001 From: Dario Manesku Date: Sun, 3 May 2015 16:20:41 +0200 Subject: [PATCH 2/2] Fixup for previous commit. --- examples/common/entry/entry_sdl.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/examples/common/entry/entry_sdl.cpp b/examples/common/entry/entry_sdl.cpp index 28ef5f01..91bfef74 100644 --- a/examples/common/entry/entry_sdl.cpp +++ b/examples/common/entry/entry_sdl.cpp @@ -450,7 +450,30 @@ namespace entry { uint8_t modifiers = translateKeyModifiers(kev.keysym.mod); Key::Enum key = translateKey(kev.keysym.scancode); - m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED); + + // TODO: These keys are not captured by SDL_TEXTINPUT. Should be probably handled by SDL_TEXTEDITING. This is a workaround for now. + if (key == 1) // Escape + { + uint8_t pressedChar[4]; + pressedChar[0] = 0x1b; + m_eventQueue.postCharEvent(handle, 1, pressedChar); + } + else if (key == 2) // Enter + { + uint8_t pressedChar[4]; + pressedChar[0] = 0x0d; + m_eventQueue.postCharEvent(handle, 1, pressedChar); + } + else if (key == 5) // Backspace + { + uint8_t pressedChar[4]; + pressedChar[0] = 0x08; + m_eventQueue.postCharEvent(handle, 1, pressedChar); + } + else + { + m_eventQueue.postKeyEvent(handle, key, modifiers, kev.state == SDL_PRESSED); + } } } break;