Numpad 2,4,6,8 != Arrow keys!

This commit is contained in:
andres.delikat 2011-06-19 23:31:58 +00:00
parent f5014946db
commit 38422fda10
3 changed files with 1174 additions and 1174 deletions

View File

@ -37,6 +37,14 @@ namespace BizHawk.MultiClient
if (control.StartsWith("J2 ")) return GetGamePad(1, control.Substring(3)); if (control.StartsWith("J2 ")) return GetGamePad(1, control.Substring(3));
if (control.StartsWith("J3 ")) return GetGamePad(2, control.Substring(3)); if (control.StartsWith("J3 ")) return GetGamePad(2, control.Substring(3));
if (control.StartsWith("J4 ")) return GetGamePad(3, control.Substring(3)); if (control.StartsWith("J4 ")) return GetGamePad(3, control.Substring(3));
//Key z = Key.n
Key z = Key.NumberPad4;
Key y = Key.LeftArrow;
if (z == Key.LeftArrow || y == Key.LeftArrow)
{
int x = 0;
x++;
}
Key k = (Key) Enum.Parse(typeof(Key), control, true); Key k = (Key) Enum.Parse(typeof(Key), control, true);
return KeyInput.IsPressed(k); return KeyInput.IsPressed(k);
} }

View File

@ -4,80 +4,72 @@ using SlimDX.DirectInput;
namespace BizHawk.MultiClient namespace BizHawk.MultiClient
{ {
public static class KeyInput public static class KeyInput
{ {
private static DirectInput dinput; private static DirectInput dinput;
private static Keyboard keyboard; private static Keyboard keyboard;
private static KeyboardState state = new KeyboardState(); private static KeyboardState state = new KeyboardState();
private static List<Key> unpressedKeys = new List<Key>(); private static List<Key> unpressedKeys = new List<Key>();
public static void Initialize()
{
if (dinput == null)
dinput = new DirectInput();
if (keyboard == null || keyboard.Disposed) public static void Initialize()
keyboard = new Keyboard(dinput); {
if (Global.Config.AcceptBackgroundInput) if (dinput == null)
keyboard.SetCooperativeLevel(Global.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive); dinput = new DirectInput();
else
keyboard.SetCooperativeLevel(Global.MainForm.Handle, CooperativeLevel.Foreground | CooperativeLevel.Nonexclusive);
}
public static void Update() if (keyboard == null || keyboard.Disposed)
{ keyboard = new Keyboard(dinput);
if (keyboard.Acquire().IsFailure) if (Global.Config.AcceptBackgroundInput)
return; keyboard.SetCooperativeLevel(Global.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
if (keyboard.Poll().IsFailure) else
return; keyboard.SetCooperativeLevel(Global.MainForm.Handle, CooperativeLevel.Foreground | CooperativeLevel.Nonexclusive);
}
state = keyboard.GetCurrentState(); public static void Update()
if (Result.Last.IsFailure) {
return; if (keyboard.Acquire().IsFailure)
return;
if (keyboard.Poll().IsFailure)
return;
unpressedKeys.RemoveAll(key => state.IsReleased(key)); state = keyboard.GetCurrentState();
} if (Result.Last.IsFailure)
return;
public static KeyboardState State { get { return state; } } unpressedKeys.RemoveAll(key => state.IsReleased(key));
}
public static void Unpress(Key key) public static KeyboardState State { get { return state; } }
{
if (unpressedKeys.Contains(key))
return;
unpressedKeys.Add(key);
}
public static bool IsPressed(Key key) public static void Unpress(Key key)
{ {
if (unpressedKeys.Contains(key)) if (unpressedKeys.Contains(key))
return false; return;
if (state.IsPressed(key)) unpressedKeys.Add(key);
return true; }
if (key == Key.UpArrow && state.IsPressed(Key.NumberPad8))
return true;
if (key == Key.DownArrow && state.IsPressed(Key.NumberPad2))
return true;
if (key == Key.LeftArrow && state.IsPressed(Key.NumberPad4))
return true;
if (key == Key.RightArrow && state.IsPressed(Key.NumberPad6))
return true;
return false;
}
public static Key? GetPressedKey() public static bool IsPressed(Key key)
{ {
// TODO uhh this will return the same key over and over though. if (unpressedKeys.Contains(key))
if (state.PressedKeys.Count == 0) return false;
return null; if (state.IsPressed(key))
if (state.PressedKeys[0] == Key.NumberPad8) return true;
return Key.UpArrow; return false;
if (state.PressedKeys[0] == Key.NumberPad2) }
return Key.DownArrow;
if (state.PressedKeys[0] == Key.NumberPad4) public static Key? GetPressedKey()
return Key.LeftArrow; {
if (state.PressedKeys[0] == Key.NumberPad6) // TODO uhh this will return the same key over and over though.
return Key.RightArrow; if (state.PressedKeys.Count == 0)
return state.PressedKeys[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];
}
}
} }

File diff suppressed because it is too large Load Diff