diff --git a/src/core/winrt/SDL_winrtapp_direct3d.cpp b/src/core/winrt/SDL_winrtapp_direct3d.cpp index fc5909aae..d91451068 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp @@ -365,6 +365,9 @@ void SDL_WinRTApp::SetWindow(CoreWindow^ window) window->KeyUp += ref new TypedEventHandler(this, &SDL_WinRTApp::OnKeyUp); + window->CharacterReceived += + ref new TypedEventHandler(this, &SDL_WinRTApp::OnCharacterReceived); + #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP HardwareButtons::BackPressed += ref new EventHandler(this, &SDL_WinRTApp::OnBackButtonPressed); @@ -703,6 +706,11 @@ void SDL_WinRTApp::OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::C WINRT_ProcessKeyUpEvent(args); } +void SDL_WinRTApp::OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args) +{ + WINRT_ProcessCharacterReceivedEvent(args); +} + #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP void SDL_WinRTApp::OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args) { diff --git a/src/core/winrt/SDL_winrtapp_direct3d.h b/src/core/winrt/SDL_winrtapp_direct3d.h index 714d41c7e..255e2b1e6 100644 --- a/src/core/winrt/SDL_winrtapp_direct3d.h +++ b/src/core/winrt/SDL_winrtapp_direct3d.h @@ -69,6 +69,7 @@ protected: void OnMouseMoved(Windows::Devices::Input::MouseDevice^ mouseDevice, Windows::Devices::Input::MouseEventArgs^ args); void OnKeyDown(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); void OnKeyUp(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::KeyEventArgs^ args); + void OnCharacterReceived(Windows::UI::Core::CoreWindow^ sender, Windows::UI::Core::CharacterReceivedEventArgs^ args); #if WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP void OnBackButtonPressed(Platform::Object^ sender, Windows::Phone::UI::Input::BackPressedEventArgs^ args); diff --git a/src/video/winrt/SDL_winrtevents_c.h b/src/video/winrt/SDL_winrtevents_c.h index 826cad74e..4e3dfb3b3 100644 --- a/src/video/winrt/SDL_winrtevents_c.h +++ b/src/video/winrt/SDL_winrtevents_c.h @@ -63,6 +63,7 @@ extern void WINRT_ProcessMouseMovedEvent(SDL_Window * window, Windows::Devices:: /* Keyboard */ extern void WINRT_ProcessKeyDownEvent(Windows::UI::Core::KeyEventArgs ^args); extern void WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args); +extern void WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args); /* XAML Thread Management */ extern void WINRT_CycleXAMLThread(); diff --git a/src/video/winrt/SDL_winrtkeyboard.cpp b/src/video/winrt/SDL_winrtkeyboard.cpp index 920e45f00..a44e5066c 100644 --- a/src/video/winrt/SDL_winrtkeyboard.cpp +++ b/src/video/winrt/SDL_winrtkeyboard.cpp @@ -365,4 +365,22 @@ WINRT_ProcessKeyUpEvent(Windows::UI::Core::KeyEventArgs ^args) SDL_SendKeyboardKey(SDL_RELEASED, sdlScancode); } +void +WINRT_ProcessCharacterReceivedEvent(Windows::UI::Core::CharacterReceivedEventArgs ^args) +{ + wchar_t src_ucs2[2]; + char dest_utf8[16]; + int result; + + /* Setup src */ + src_ucs2[0] = args->KeyCode; + src_ucs2[1] = L'\0'; + + /* Convert the text, then send an SDL_TEXTINPUT event. */ + result = WideCharToMultiByte(CP_UTF8, 0, (LPCWSTR)&src_ucs2, -1, (LPSTR)dest_utf8, sizeof(dest_utf8), NULL, NULL); + if (result > 0) { + SDL_SendKeyboardText(dest_utf8); + } +} + #endif // SDL_VIDEO_DRIVER_WINRT