Permalink
Browse files

Merge pull request #4290 from pchote/text-fix

Attempt to parse unexpected key events as text.
  • Loading branch information...
2 parents 0c19912 + 719c9c1 commit f76caa5fb700dc9104847c6035c3ae09d35634b1 @Mailaender Mailaender committed Dec 11, 2013
Showing with 16 additions and 7 deletions.
  1. +0 −6 OpenRA.FileFormats/Exts.cs
  2. +16 −1 OpenRA.Renderer.SdlCommon/SdlInput.cs
@@ -82,12 +82,6 @@ public static bool HasModifier(this Modifiers k, Modifiers mod)
return (k & mod) == mod;
}
- public static bool IsValidInput(this KeyInput key)
- {
- return char.IsLetter(key.UnicodeChar) || char.IsDigit(key.UnicodeChar) ||
- char.IsSymbol(key.UnicodeChar) || char.IsSeparator(key.UnicodeChar) ||
- char.IsPunctuation(key.UnicodeChar);
- }
public static V GetOrAdd<K, V>(this Dictionary<K, V> d, K k)
where V : new()
@@ -151,8 +151,16 @@ public class SdlInput
{ Sdl.SDLK_UNDO, Keycode.UNDO },
};
+
MouseButton lastButtonBits = (MouseButton)0;
+ static bool IsValidInput(char c)
+ {
+ return char.IsLetter(c) || char.IsDigit(c) ||
+ char.IsSymbol(c) || char.IsSeparator(c) ||
+ char.IsPunctuation(c);
+ }
+
MouseButton MakeButton(byte b)
{
return b == Sdl.SDL_BUTTON_LEFT ? MouseButton.Left
@@ -242,7 +250,14 @@ public void PumpInput(IInputHandler inputHandler)
// Drop unknown keys
Keycode keyCode;
if (!KeyRemap.TryGetValue(e.key.keysym.sym, out keyCode))
+ {
+ // Try parsing it as text
+ var c = (char)e.key.keysym.unicode;
+ if (IsValidInput(c))
+ inputHandler.OnTextInput(c.ToString());
+
break;
+ }
var type = e.type == Sdl.SDL_KEYDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
@@ -269,7 +284,7 @@ public void PumpInput(IInputHandler inputHandler)
else
inputHandler.OnKeyInput(keyEvent);
- if (keyEvent.IsValidInput())
+ if (IsValidInput(keyEvent.UnicodeChar))
inputHandler.OnTextInput(keyEvent.UnicodeChar.ToString());
break;

0 comments on commit f76caa5

Please sign in to comment.