GetPressedKey() progress, returns keyboard with desired modifier-key properties

This commit is contained in:
beirich 2011-07-04 23:36:06 +00:00
parent 02e562825e
commit a3df5345f6
2 changed files with 72 additions and 14 deletions

View File

@ -99,9 +99,7 @@ namespace BizHawk.MultiClient
}
}
// TODO: poll keyboard input
return null;
return KeyInput.GetPressedKey();
}
}
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Text;
using SlimDX;
using SlimDX.DirectInput;
@ -64,20 +65,79 @@ namespace BizHawk.MultiClient
return false;
}
public static Key? GetPressedKey()
public static string GetPressedKey()
{
// TODO uhh this will return the same key over and over though.
if (state.PressedKeys.Count == 0)
return null;
if (state.PressedKeys[0] == Key.NumberPad8)
return Key.UpArrow;
if (state.PressedKeys[0] == Key.NumberPad2)
return Key.DownArrow;
if (state.PressedKeys[0] == Key.NumberPad4)
return Key.LeftArrow;
if (state.PressedKeys[0] == Key.NumberPad6)
return Key.RightArrow;
return state.PressedKeys[0];
Key? key = null;
for (int i=0; i<state.PressedKeys.Count; i++)
{
if (state.PressedKeys[i].IsModifier())
continue;
key = state.PressedKeys[i];
break;
}
if (key == null)
return null;
string keystr = GetModifierKeys() ?? "";
return keystr + key;
}
public static bool ShiftModifier
{
get
{
if (state.IsPressed(Key.LeftShift)) return true;
if (state.IsPressed(Key.RightShift)) return true;
return false;
}
}
public static bool CtrlModifier
{
get
{
if (state.IsPressed(Key.LeftControl)) return true;
if (state.IsPressed(Key.RightControl)) return true;
return false;
}
}
public static bool AltModifier
{
get
{
if (state.IsPressed(Key.LeftAlt)) return true;
if (state.IsPressed(Key.RightAlt)) return true;
return false;
}
}
public static string GetModifierKeys()
{
StringBuilder sb = new StringBuilder(16);
if (ShiftModifier) sb.Append("Shift+");
if (CtrlModifier) sb.Append("Ctrl+");
if (AltModifier) sb.Append("Alt+");
if (sb.Length == 0) return null;
return sb.ToString();
}
}
internal static class KeyExtensions
{
public static bool IsModifier(this Key key)
{
if (key == Key.LeftShift) return true;
if (key == Key.RightShift) return true;
if (key == Key.LeftControl) return true;
if (key == Key.RightControl) return true;
if (key == Key.LeftAlt) return true;
if (key == Key.RightAlt) return true;
return false;
}
}
}