Remove VirtKey and KeyName.

This commit is contained in:
Paul Chote
2013-10-20 18:16:33 +13:00
parent e5f93ec39e
commit aab6fec68b
13 changed files with 54 additions and 70 deletions

View File

@@ -14,8 +14,8 @@ using OpenRA.FileFormats;
public static class MultiTapDetection
{
static Cache<string, TapHistory> keyHistoryCache =
new Cache<string, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
static Cache<Keycode, TapHistory> keyHistoryCache =
new Cache<Keycode, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
static Cache<byte, TapHistory> clickHistoryCache =
new Cache<byte, TapHistory>(_ => new TapHistory(DateTime.Now - TimeSpan.FromSeconds(1)));
@@ -29,12 +29,12 @@ public static class MultiTapDetection
return clickHistoryCache[button].LastTapCount();
}
public static int DetectFromKeyboard(string key)
public static int DetectFromKeyboard(Keycode key)
{
return keyHistoryCache[key].GetTapCount(int2.Zero);
}
public static int InfoFromKeyboard(string key)
public static int InfoFromKeyboard(Keycode key)
{
return keyHistoryCache[key].LastTapCount();
}

View File

@@ -102,18 +102,23 @@ namespace OpenRA.Renderer.SdlCommon
}
case Sdl.SDL_KEYDOWN:
case Sdl.SDL_KEYUP:
{
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
var keyCode = (Keycode)e.key.keysym.sym;
var type = e.type == Sdl.SDL_KEYDOWN ?
KeyInputEvent.Down : KeyInputEvent.Up;
var tapCount = e.type == Sdl.SDL_KEYDOWN ?
MultiTapDetection.DetectFromKeyboard(keyCode) :
MultiTapDetection.InfoFromKeyboard(keyCode);
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Down,
Key = (Keycode)e.key.keysym.sym,
Event = type,
Key = keyCode,
Modifiers = mods,
UnicodeChar = (char)e.key.keysym.unicode,
MultiTapCount = MultiTapDetection.DetectFromKeyboard(keyName),
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
VirtKey = e.key.keysym.sym
MultiTapCount = tapCount
};
// Special case workaround for windows users
@@ -127,24 +132,6 @@ namespace OpenRA.Renderer.SdlCommon
break;
}
case Sdl.SDL_KEYUP:
{
var keyName = Sdl.SDL_GetKeyName(e.key.keysym.sym);
var keyEvent = new KeyInput
{
Event = KeyInputEvent.Up,
Key = (Keycode)e.key.keysym.sym,
Modifiers = mods,
UnicodeChar = (char)e.key.keysym.unicode,
MultiTapCount = MultiTapDetection.InfoFromKeyboard(keyName),
KeyName = Sdl.SDL_GetKeyName(e.key.keysym.sym),
VirtKey = e.key.keysym.sym
};
inputHandler.OnKeyInput(keyEvent);
break;
}
}
}