diff --git a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs index 247abbdd..0a55e127 100644 --- a/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs +++ b/Source/OpenTK/Platform/SDL2/Sdl2NativeWindow.cs @@ -37,6 +37,7 @@ using System.Drawing.Imaging; using System.Runtime.InteropServices; using OpenTK; using OpenTK.Input; +using System.Text; namespace OpenTK.Platform.SDL2 { @@ -150,6 +151,14 @@ namespace OpenTK.Platform.SDL2 } break; + case EventType.TEXTINPUT: + if (windows.TryGetValue(ev.Text.WindowID, out window)) + { + ProcessTextInputEvent(window, ev.Text); + processed = true; + } + break; + case EventType.KEYDOWN: case EventType.KEYUP: if (windows.TryGetValue(ev.Key.WindowID, out window)) @@ -226,6 +235,30 @@ namespace OpenTK.Platform.SDL2 //window.keyboard.SetKey(TranslateKey(key.scancode), (uint)key.scancode, key_pressed); } + static unsafe void ProcessTextInputEvent(Sdl2NativeWindow window, TextInputEvent ev) + { + var keyPress = window.KeyPress; + if (keyPress != null) + { + var length = 0; + byte* pText = ev.Text; + while (*pText != 0) + { + length++; + pText++; + } + using (var stream = new System.IO.UnmanagedMemoryStream(ev.Text, length)) + using (var reader = new System.IO.StreamReader(stream, Encoding.UTF8)) + { + var text = reader.ReadToEnd(); + foreach (var c in text) + { + keyPress(window, new KeyPressEventArgs(c)); + } + } + } + } + static void ProcessMotionEvent(Sdl2NativeWindow window, Event ev) { float scale = window.ClientSize.Width / (float)window.Size.Width;