2011-01-11 02:55:51 +00:00
|
|
|
|
using System.Collections.Generic;
|
2011-07-04 23:36:06 +00:00
|
|
|
|
using System.Text;
|
2011-01-11 02:55:51 +00:00
|
|
|
|
using SlimDX;
|
|
|
|
|
using SlimDX.DirectInput;
|
|
|
|
|
|
|
|
|
|
namespace BizHawk.MultiClient
|
|
|
|
|
{
|
2011-06-19 23:31:58 +00:00
|
|
|
|
public static class KeyInput
|
|
|
|
|
{
|
|
|
|
|
private static DirectInput dinput;
|
|
|
|
|
private static Keyboard keyboard;
|
|
|
|
|
private static KeyboardState state = new KeyboardState();
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
public static void Initialize()
|
|
|
|
|
{
|
2011-07-08 05:15:28 +00:00
|
|
|
|
if (dinput == null)
|
2011-06-19 23:31:58 +00:00
|
|
|
|
dinput = new DirectInput();
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
if (keyboard == null || keyboard.Disposed)
|
|
|
|
|
keyboard = new Keyboard(dinput);
|
2011-07-08 05:15:28 +00:00
|
|
|
|
keyboard.SetCooperativeLevel(Global.MainForm.Handle, CooperativeLevel.Background | CooperativeLevel.Nonexclusive);
|
2011-06-19 23:31:58 +00:00
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
public static void Update()
|
|
|
|
|
{
|
|
|
|
|
if (keyboard.Acquire().IsFailure)
|
|
|
|
|
return;
|
|
|
|
|
if (keyboard.Poll().IsFailure)
|
|
|
|
|
return;
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
state = keyboard.GetCurrentState();
|
|
|
|
|
if (Result.Last.IsFailure)
|
|
|
|
|
return;
|
|
|
|
|
}
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
public static KeyboardState State { get { return state; } }
|
2011-01-11 02:55:51 +00:00
|
|
|
|
|
2011-07-10 06:24:04 +00:00
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
public static bool IsPressed(Key key)
|
|
|
|
|
{
|
|
|
|
|
if (state.IsPressed(key))
|
|
|
|
|
return true;
|
2011-06-20 02:24:41 +00:00
|
|
|
|
|
|
|
|
|
if (key == Key.LeftShift && state.IsPressed(Key.RightShift))
|
|
|
|
|
return true;
|
|
|
|
|
if (key == Key.LeftControl && state.IsPressed(Key.RightControl))
|
|
|
|
|
return true;
|
|
|
|
|
if (key == Key.LeftAlt && state.IsPressed(Key.RightAlt))
|
|
|
|
|
return true;
|
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-04 23:36:06 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-10 02:14:58 +00:00
|
|
|
|
public static Input.ModifierKey GetModifierKeysAsKeys()
|
2011-07-09 22:09:39 +00:00
|
|
|
|
{
|
2011-07-10 02:14:58 +00:00
|
|
|
|
Input.ModifierKey ret = Input.ModifierKey.None;
|
|
|
|
|
if (ShiftModifier) ret |= Input.ModifierKey.Shift;
|
|
|
|
|
if (CtrlModifier) ret |= Input.ModifierKey.Control;
|
|
|
|
|
if (AltModifier) ret |= Input.ModifierKey.Alt;
|
2011-07-09 22:09:39 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-19 23:31:58 +00:00
|
|
|
|
}
|
2011-07-04 23:36:06 +00:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-03-12 04:44:34 +00:00
|
|
|
|
}
|