/trunk/WingMan/Bindings/ExecuteKeyBinding.cs |
@@ -1,23 +1,22 @@ |
using System.Xml.Serialization; |
using ProtoBuf; |
|
namespace WingMan.Bindings |
{ |
[ProtoContract] |
public class ExecuteKeyBinding |
{ |
[XmlIgnore] public static readonly XmlSerializer XmlSerializer = |
new XmlSerializer(typeof(ExecuteKeyBinding)); |
|
public ExecuteKeyBinding() |
{ |
} |
|
public ExecuteKeyBinding(string nick, string name) |
public ExecuteKeyBinding(string nick, string name) : this() |
{ |
Nick = nick; |
Name = name; |
} |
|
public string Nick { get; set; } |
public string Name { get; set; } |
[ProtoMember(1)] public string Nick { get; set; } |
|
[ProtoMember(2)] public string Name { get; set; } |
} |
} |
} |
/trunk/WingMan/Bindings/KeyBindingExchange.cs |
@@ -1,25 +1,30 @@ |
using System.Collections.Generic; |
using System.Xml.Serialization; |
using ProtoBuf; |
|
namespace WingMan.Bindings |
{ |
[ProtoContract] |
public class KeyBindingExchange |
{ |
[XmlIgnore] public static readonly XmlSerializer XmlSerializer = |
new XmlSerializer(typeof(KeyBindingExchange)); |
private readonly List<string> _keyBindings = new List<string>(); |
|
public KeyBindingExchange() |
{ |
} |
|
public KeyBindingExchange(string nick, List<KeyBinding> keyBindings) |
public KeyBindingExchange(string nick, List<string> keyBindings) : this() |
{ |
Nick = nick; |
KeyBindings = keyBindings; |
} |
|
public string Nick { get; set; } |
[ProtoMember(1)] public string Nick { get; set; } |
|
public List<KeyBinding> KeyBindings { get; set; } |
[ProtoMember(2)] |
public List<string> KeyBindings |
{ |
get => _keyBindings; |
set => _keyBindings.AddRange(value); |
} |
} |
} |
} |
/trunk/WingMan/Bindings/KeyBindingsSynchronizer.cs |
@@ -5,6 +5,7 @@ |
using System.Linq; |
using System.Threading; |
using System.Threading.Tasks; |
using ProtoBuf; |
using WingMan.Communication; |
|
namespace WingMan.Bindings |
@@ -21,7 +22,7 @@ |
CancellationToken = cancellationToken; |
TaskScheduler = taskScheduler; |
|
SynchronizedMouseKeyBindings = new ConcurrentDictionary<string, List<KeyBinding>>(); |
SynchronizedMouseKeyBindings = new ConcurrentDictionary<string, List<string>>(); |
|
MqttCommunication.OnMessageReceived += MqttCommunicationOnMessageReceived; |
|
@@ -30,7 +31,7 @@ |
|
private LocalKeyBindings LocalKeyBindings { get; } |
|
private ConcurrentDictionary<string, List<KeyBinding>> SynchronizedMouseKeyBindings { get; } |
private ConcurrentDictionary<string, List<string>> SynchronizedMouseKeyBindings { get; } |
|
private MqttCommunication MqttCommunication { get; } |
|
@@ -57,7 +58,7 @@ |
memoryStream.Position = 0L; |
|
var mouseKeyBindingsExchange = |
(KeyBindingExchange) KeyBindingExchange.XmlSerializer.Deserialize(memoryStream); |
Serializer.Deserialize<KeyBindingExchange>(memoryStream); |
|
// Do not add own bindings. |
if (string.Equals(mouseKeyBindingsExchange.Nick, MqttCommunication.Nick)) |
@@ -91,8 +92,9 @@ |
|
using (var memoryStream = new MemoryStream()) |
{ |
KeyBindingExchange.XmlSerializer.Serialize(memoryStream, |
new KeyBindingExchange(MqttCommunication.Nick, LocalKeyBindings.Bindings)); |
Serializer.Serialize(memoryStream, |
new KeyBindingExchange(MqttCommunication.Nick, |
LocalKeyBindings.Bindings.Select(binding => binding.Name).ToList())); |
|
memoryStream.Position = 0L; |
|
/trunk/WingMan/Bindings/KeyInterceptor.cs |
@@ -7,6 +7,7 @@ |
using System.Threading.Tasks.Dataflow; |
using System.Windows.Forms; |
using Gma.System.MouseKeyHook; |
using ProtoBuf; |
using WingMan.Communication; |
using WingMan.Utilities; |
|
@@ -16,7 +17,7 @@ |
{ |
public delegate void MouseKeyBindingMatched(object sender, KeyBindingMatchedEventArgs args); |
|
private volatile bool ProcessPipe; |
private volatile bool _processPipe; |
|
public KeyInterceptor(RemoteKeyBindings remoteKeyBindings, MqttCommunication mqttCommunication, |
TaskScheduler taskScheduler, CancellationToken cancellationToken) |
@@ -98,7 +99,7 @@ |
|
try |
{ |
if (!ProcessPipe) |
if (!_processPipe) |
return; |
|
foreach (var binding in RemoteKeyBindings.Bindings) |
@@ -116,7 +117,7 @@ |
|
using (var memoryStream = new MemoryStream()) |
{ |
ExecuteKeyBinding.XmlSerializer.Serialize(memoryStream, |
Serializer.Serialize(memoryStream, |
new ExecuteKeyBinding(binding.Nick, binding.Name)); |
|
memoryStream.Position = 0L; |
@@ -135,7 +136,7 @@ |
|
private async void MouseKeyGloalHookOnKeyDown(object sender, KeyEventArgs e) |
{ |
ProcessPipe = true; |
_processPipe = true; |
|
if (!KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key)) |
return; |
@@ -154,7 +155,7 @@ |
|
private void MouseKeyGloalHookOnKeyUp(object sender, KeyEventArgs e) |
{ |
ProcessPipe = false; |
_processPipe = false; |
} |
} |
} |
} |
/trunk/WingMan/Bindings/KeySimulator.cs |
@@ -4,6 +4,7 @@ |
using System.Threading.Tasks; |
using WindowsInput; |
using WindowsInput.Native; |
using ProtoBuf; |
using WingMan.Communication; |
using WingMan.Utilities; |
|
@@ -52,7 +53,7 @@ |
memoryStream.Position = 0L; |
|
var executeMouseKeyBinding = |
(ExecuteKeyBinding) ExecuteKeyBinding.XmlSerializer.Deserialize(memoryStream); |
Serializer.Deserialize<ExecuteKeyBinding>(memoryStream); |
|
// Do not process own mouse key bindings. |
if (!string.Equals(executeMouseKeyBinding.Nick, MqttCommunication.Nick, StringComparison.Ordinal)) |