diff --git a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
index b6329ea68b..6b2e6aa74a 100644
--- a/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
+++ b/BizHawk.Client.EmuHawk/BizHawk.Client.EmuHawk.csproj
@@ -547,6 +547,7 @@
+
diff --git a/BizHawk.Client.EmuHawk/Input/IPCKeyInput.cs b/BizHawk.Client.EmuHawk/Input/IPCKeyInput.cs
new file mode 100644
index 0000000000..01c42c9626
--- /dev/null
+++ b/BizHawk.Client.EmuHawk/Input/IPCKeyInput.cs
@@ -0,0 +1,64 @@
+using System.Collections.Generic;
+using System.IO;
+using System;
+using System.Threading;
+using System.IO.Pipes;
+using SlimDX;
+using SlimDX.DirectInput;
+
+//this is not a very safe or pretty protocol, I'm not proud of it
+
+namespace BizHawk.Client.EmuHawk
+{
+ public static class IPCKeyInput
+ {
+ public static void Initialize()
+ {
+ var t = new Thread(IPCThread);
+ t.IsBackground = true;
+ t.Start();
+ }
+
+
+ static List PendingEventList = new List();
+ static List EventList = new List();
+
+ static void IPCThread()
+ {
+ string pipeName = string.Format("bizhawk-pid-{0}-IPCKeyInput", System.Diagnostics.Process.GetCurrentProcess().Id);
+
+
+ for (; ; )
+ {
+ using (NamedPipeServerStream pipe = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024))
+ {
+ try
+ {
+ pipe.WaitForConnection();
+
+ BinaryReader br = new BinaryReader(pipe);
+
+ for (; ; )
+ {
+ int e = br.ReadInt32();
+ bool pressed = (e & 0x80000000) != 0;
+ lock (PendingEventList)
+ PendingEventList.Add(new KeyInput.KeyEvent { Key = (Key)(e & 0x7FFFFFFF), Pressed = pressed });
+ }
+ }
+ catch { }
+ }
+ }
+ }
+
+ public static IEnumerable Update()
+ {
+ EventList.Clear();
+
+ lock (PendingEventList)
+ EventList.AddRange(PendingEventList);
+
+ return EventList;
+ }
+ }
+}
diff --git a/BizHawk.Client.EmuHawk/Input/Input.cs b/BizHawk.Client.EmuHawk/Input/Input.cs
index 245d993ee6..c9e7a18d77 100644
--- a/BizHawk.Client.EmuHawk/Input/Input.cs
+++ b/BizHawk.Client.EmuHawk/Input/Input.cs
@@ -128,6 +128,7 @@ namespace BizHawk.Client.EmuHawk
{
#if WINDOWS
KeyInput.Initialize();
+ IPCKeyInput.Initialize();
GamePad.Initialize();
GamePad360.Initialize();
#endif
@@ -319,7 +320,7 @@ namespace BizHawk.Client.EmuHawk
{
for (; ; )
{
- var keyEvents = KeyInput.Update();
+ var keyEvents = KeyInput.Update().Concat(IPCKeyInput.Update());
GamePad.UpdateAll();
GamePad360.UpdateAll();
diff --git a/BizHawk.Client.EmuHawk/Input/Keyboard.cs b/BizHawk.Client.EmuHawk/Input/Keyboard.cs
index 8fc42ebeb1..2cfecdd1f5 100644
--- a/BizHawk.Client.EmuHawk/Input/Keyboard.cs
+++ b/BizHawk.Client.EmuHawk/Input/Keyboard.cs
@@ -12,7 +12,7 @@ namespace BizHawk.Client.EmuHawk
public static void Initialize()
{
- if (dinput == null)
+ if (dinput == null)
dinput = new DirectInput();
if (keyboard == null || keyboard.Disposed)
@@ -45,7 +45,7 @@ namespace BizHawk.Client.EmuHawk
foreach (var k in e.PressedKeys)
EventList.Add(new KeyEvent { Key = k, Pressed = true });
foreach (var k in e.ReleasedKeys)
- EventList.Add(new KeyEvent { Key = k, Pressed = false });
+ EventList.Add(new KeyEvent { Key = k, Pressed = false });
}
}
@@ -58,74 +58,5 @@ namespace BizHawk.Client.EmuHawk
public bool Pressed;
}
-
- public static bool IsPressed(Key key)
- {
- if (state.IsPressed(key))
- return true;
-
- 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;
-
- return false;
- }
-
- 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 Input.ModifierKey GetModifierKeysAsKeys()
- {
- Input.ModifierKey ret = Input.ModifierKey.None;
- if (ShiftModifier) ret |= Input.ModifierKey.Shift;
- if (CtrlModifier) ret |= Input.ModifierKey.Control;
- if (AltModifier) ret |= Input.ModifierKey.Alt;
- return ret;
- }
-
}
-
- 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;
- }
- }
}