\r
#include "CIrrDeviceSDL.h"\r
#include "IEventReceiver.h"\r
+#include "IGUIElement.h"\r
+#include "IGUIEnvironment.h"\r
#include "os.h"\r
#include "CTimer.h"\r
#include "irrString.h"\r
}\r
#endif\r
\r
+\r
+bool CIrrDeviceSDL::keyIsKnownSpecial(EKEY_CODE key)\r
+{\r
+ switch ( key )\r
+ {\r
+ // keys which are known to have safe special character interpretation\r
+ // could need changes over time (removals and additions!)\r
+ case KEY_RETURN:\r
+ case KEY_PAUSE:\r
+ case KEY_ESCAPE:\r
+ case KEY_PRIOR:\r
+ case KEY_NEXT:\r
+ case KEY_HOME:\r
+ case KEY_END:\r
+ case KEY_LEFT:\r
+ case KEY_UP:\r
+ case KEY_RIGHT:\r
+ case KEY_DOWN:\r
+ case KEY_TAB:\r
+ case KEY_PRINT:\r
+ case KEY_SNAPSHOT:\r
+ case KEY_INSERT:\r
+ case KEY_BACK:\r
+ case KEY_DELETE:\r
+ case KEY_HELP:\r
+ case KEY_APPS:\r
+ case KEY_SLEEP:\r
+ case KEY_F1:\r
+ case KEY_F2:\r
+ case KEY_F3:\r
+ case KEY_F4:\r
+ case KEY_F5:\r
+ case KEY_F6:\r
+ case KEY_F7:\r
+ case KEY_F8:\r
+ case KEY_F9:\r
+ case KEY_F10:\r
+ case KEY_F11:\r
+ case KEY_F12:\r
+ case KEY_F13:\r
+ case KEY_F14:\r
+ case KEY_F15:\r
+ case KEY_F16:\r
+ case KEY_F17:\r
+ case KEY_F18:\r
+ case KEY_F19:\r
+ case KEY_F20:\r
+ case KEY_F21:\r
+ case KEY_F22:\r
+ case KEY_F23:\r
+ case KEY_F24:\r
+ case KEY_NUMLOCK:\r
+ case KEY_SCROLL:\r
+ case KEY_LCONTROL:\r
+ case KEY_RCONTROL:\r
+ return true;\r
+\r
+ default:\r
+ return false;\r
+ }\r
+}\r
+\r
+int CIrrDeviceSDL::findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key) {\r
+ // SDL in-place ORs values with no character representation with 1<<30\r
+ // https://wiki.libsdl.org/SDL2/SDLKeycodeLookup\r
+ if (assumedChar & (1<<30))\r
+ return 0;\r
+\r
+ switch (key) {\r
+ case KEY_PRIOR:\r
+ case KEY_NEXT:\r
+ case KEY_HOME:\r
+ case KEY_END:\r
+ case KEY_LEFT:\r
+ case KEY_UP:\r
+ case KEY_RIGHT:\r
+ case KEY_DOWN:\r
+ case KEY_NUMLOCK:\r
+ return 0;\r
+ default:\r
+ return assumedChar;\r
+ }\r
+}\r
+\r
+void CIrrDeviceSDL::resetReceiveTextInputEvents() {\r
+ gui::IGUIElement *elem = GUIEnvironment->getFocus();\r
+ if (elem && elem->acceptsIME())\r
+ SDL_StartTextInput();\r
+ else\r
+ SDL_StopTextInput();\r
+}\r
+\r
//! constructor\r
CIrrDeviceSDL::CIrrDeviceSDL(const SIrrlichtCreationParameters& param)\r
: CIrrDeviceStub(param),\r
else\r
key = (EKEY_CODE)KeyMap[idx].Win32Key;\r
\r
+ // Make sure to only input special characters if something is in focus, as SDL_TEXTINPUT handles normal unicode already\r
+ if (SDL_IsTextInputActive() && !keyIsKnownSpecial(key) && (SDL_event.key.keysym.mod & KMOD_CTRL) == 0)\r
+ break;\r
+\r
#ifdef _IRR_WINDOWS_API_\r
// handle alt+f4 in Windows, because SDL seems not to\r
if ( (SDL_event.key.keysym.mod & KMOD_LALT) && key == KEY_F4)\r
irrevent.KeyInput.PressedDown = (SDL_event.type == SDL_KEYDOWN);\r
irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;\r
irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL ) != 0;\r
- // These keys are handled differently in CGUIEditBox.cpp (may become out of date!)\r
- // Control key is used in special character combinations, so keep that too\r
- // Pass through the keysym only then so no extra text gets input\r
- irrevent.KeyInput.Char = 0;\r
- if (mp.SDLKey == SDLK_DELETE || mp.SDLKey == SDLK_RETURN || mp.SDLKey == SDLK_BACKSPACE || irrevent.KeyInput.Control)\r
- irrevent.KeyInput.Char = mp.SDLKey;\r
+ irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key);\r
postEventFromUser(irrevent);\r
}\r
break;\r
default:\r
break;\r
} // end switch\r
-\r
+ resetReceiveTextInputEvents();\r
} // end while\r
\r
#if defined(_IRR_COMPILE_WITH_JOYSTICK_EVENTS_)\r
static EM_BOOL MouseLeaveCallback(int eventType, const EmscriptenMouseEvent *mouseEvent, void *userData);\r
\r
#endif\r
+ // Check if a key is a known special character with no side effects on text boxes.\r
+ static bool keyIsKnownSpecial(EKEY_CODE key);\r
+\r
+ // Return the Char that should be sent to Irrlicht for the given key (either the one passed in or 0).\r
+ static int findCharToPassToIrrlicht(int assumedChar, EKEY_CODE key);\r
+\r
+ // Check if a text box is in focus. Enable or disable SDL_TEXTINPUT events only if in focus.\r
+ void resetReceiveTextInputEvents();\r
+\r
//! create the driver\r
void createDriver();\r
\r