2015-08-14 23:07:19 +00:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Threading;
|
|
|
|
|
using System.IO.Pipes;
|
|
|
|
|
using SlimDX.DirectInput;
|
|
|
|
|
|
2019-12-31 16:17:55 +00:00
|
|
|
|
// this is not a very safe or pretty protocol, I'm not proud of it
|
2015-08-14 23:07:19 +00:00
|
|
|
|
namespace BizHawk.Client.EmuHawk
|
|
|
|
|
{
|
|
|
|
|
public static class IPCKeyInput
|
|
|
|
|
{
|
|
|
|
|
public static void Initialize()
|
|
|
|
|
{
|
2019-12-31 16:17:55 +00:00
|
|
|
|
var t = new Thread(IPCThread) { IsBackground = true };
|
2015-08-14 23:07:19 +00:00
|
|
|
|
t.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
Simplify Windows prereqs (see desc.)
* Changed default sound/display methods to OpenAL/OpenGL on Windows to match
non-Windows, and replaced DirectInput with OpenTK input (needs regression
testing on Windows).
* (meta) As a result of the above, DirectX is no longer a prerequisite, leaving
only: .NET Framework 4.6.1 (comes with Win10, as does 4.8), MSVC 14 (also comes
with Win10), MSVC 12 for Mupen, and MSVC 10 for BSNES/Mupen.
* Refactored static Program ctor, using ExceptionBox for missing prereqs, and
removed PrereqsAlert.
* Added OS version check for Windows, with a flag in the config to skip it.
* Updated readme for Win7 EOL (and generally cleanup Windows sections).
2020-01-08 20:36:25 +00:00
|
|
|
|
private static readonly List<KeyEvent> PendingEventList = new List<KeyEvent>();
|
|
|
|
|
private static readonly List<KeyEvent> EventList = new List<KeyEvent>();
|
2015-08-14 23:07:19 +00:00
|
|
|
|
|
|
|
|
|
static void IPCThread()
|
|
|
|
|
{
|
2019-03-18 14:06:37 +00:00
|
|
|
|
string pipeName = $"bizhawk-pid-{System.Diagnostics.Process.GetCurrentProcess().Id}-IPCKeyInput";
|
2015-08-14 23:07:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (; ; )
|
|
|
|
|
{
|
2019-12-31 16:17:55 +00:00
|
|
|
|
using var pipe = new NamedPipeServerStream(pipeName, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous, 1024, 1024);
|
|
|
|
|
try
|
2015-08-14 23:07:19 +00:00
|
|
|
|
{
|
2019-12-31 16:17:55 +00:00
|
|
|
|
pipe.WaitForConnection();
|
2015-08-14 23:07:19 +00:00
|
|
|
|
|
2019-12-31 16:17:55 +00:00
|
|
|
|
BinaryReader br = new BinaryReader(pipe);
|
2015-08-14 23:07:19 +00:00
|
|
|
|
|
2019-12-31 16:17:55 +00:00
|
|
|
|
for (; ; )
|
|
|
|
|
{
|
|
|
|
|
int e = br.ReadInt32();
|
|
|
|
|
bool pressed = (e & 0x80000000) != 0;
|
|
|
|
|
lock (PendingEventList)
|
Simplify Windows prereqs (see desc.)
* Changed default sound/display methods to OpenAL/OpenGL on Windows to match
non-Windows, and replaced DirectInput with OpenTK input (needs regression
testing on Windows).
* (meta) As a result of the above, DirectX is no longer a prerequisite, leaving
only: .NET Framework 4.6.1 (comes with Win10, as does 4.8), MSVC 14 (also comes
with Win10), MSVC 12 for Mupen, and MSVC 10 for BSNES/Mupen.
* Refactored static Program ctor, using ExceptionBox for missing prereqs, and
removed PrereqsAlert.
* Added OS version check for Windows, with a flag in the config to skip it.
* Updated readme for Win7 EOL (and generally cleanup Windows sections).
2020-01-08 20:36:25 +00:00
|
|
|
|
PendingEventList.Add(new KeyEvent { Key = KeyInput.KeyEnumMap[(Key)(e & 0x7FFFFFFF)], Pressed = pressed });
|
2015-08-14 23:07:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-31 16:17:55 +00:00
|
|
|
|
catch { }
|
2015-08-14 23:07:19 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Simplify Windows prereqs (see desc.)
* Changed default sound/display methods to OpenAL/OpenGL on Windows to match
non-Windows, and replaced DirectInput with OpenTK input (needs regression
testing on Windows).
* (meta) As a result of the above, DirectX is no longer a prerequisite, leaving
only: .NET Framework 4.6.1 (comes with Win10, as does 4.8), MSVC 14 (also comes
with Win10), MSVC 12 for Mupen, and MSVC 10 for BSNES/Mupen.
* Refactored static Program ctor, using ExceptionBox for missing prereqs, and
removed PrereqsAlert.
* Added OS version check for Windows, with a flag in the config to skip it.
* Updated readme for Win7 EOL (and generally cleanup Windows sections).
2020-01-08 20:36:25 +00:00
|
|
|
|
public static IEnumerable<KeyEvent> Update()
|
2015-08-14 23:07:19 +00:00
|
|
|
|
{
|
|
|
|
|
EventList.Clear();
|
|
|
|
|
|
|
|
|
|
lock (PendingEventList)
|
2015-08-15 00:10:55 +00:00
|
|
|
|
{
|
2015-08-14 23:07:19 +00:00
|
|
|
|
EventList.AddRange(PendingEventList);
|
2015-08-15 00:10:55 +00:00
|
|
|
|
PendingEventList.Clear();
|
|
|
|
|
}
|
2015-08-14 23:07:19 +00:00
|
|
|
|
|
|
|
|
|
return EventList;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|