WingMan – Diff between revs 9 and 10
?pathlinks?
Rev 9 | Rev 10 | |||
---|---|---|---|---|
Line 36... | Line 36... | |||
36 | MqttCommunication.OnServerStopped += OnMqttServerStopped; |
36 | MqttCommunication.OnServerStopped += OnMqttServerStopped; |
|
37 | MqttCommunication.OnServerStarted += OnMqttServerStarted; |
37 | MqttCommunication.OnServerStarted += OnMqttServerStarted; |
|
38 | MqttCommunication.OnServerClientConnected += OnMqttServerClientConnected; |
38 | MqttCommunication.OnServerClientConnected += OnMqttServerClientConnected; |
|
39 | MqttCommunication.OnServerClientDisconnected += OnMqttServerClientDisconnected; |
39 | MqttCommunication.OnServerClientDisconnected += OnMqttServerClientDisconnected; |
|
Line 40... | Line 40... | |||
40 | |
40 | |
|
41 | LocalMouseKeyBindings = new MouseKeyBindings(new List<MouseKeyBinding>()); |
41 | LocalKeyBindings = new LocalKeyBindings(new List<KeyBinding>()); |
|
Line 42... | Line 42... | |||
42 | RemoteMouseKeyBindings = new RemoteMouseKeyBindings(new List<RemoteMouseKeyBinding>()); |
42 | RemoteKeyBindings = new RemoteKeyBindings(new List<RemoteKeyBinding>()); |
|
43 | |
43 | |
|
44 | LocalListBoxBindingSource = new BindingSource |
44 | LocalListBoxBindingSource = new BindingSource |
|
45 | { |
45 | { |
|
46 | DataSource = LocalMouseKeyBindings.Bindings |
46 | DataSource = LocalKeyBindings.Bindings |
|
47 | }; |
47 | }; |
|
48 | LocalBindingsListBox.DisplayMember = "DisplayName"; |
48 | LocalBindingsListBox.DisplayMember = "DisplayName"; |
|
Line 49... | Line 49... | |||
49 | LocalBindingsListBox.ValueMember = "Keys"; |
49 | LocalBindingsListBox.ValueMember = "Keys"; |
|
50 | LocalBindingsListBox.DataSource = LocalListBoxBindingSource; |
50 | LocalBindingsListBox.DataSource = LocalListBoxBindingSource; |
|
51 | |
51 | |
|
52 | MouseKeyBindingsExchange = new MouseKeyBindingsExchange |
52 | KeyBindingsExchange = new KeyBindingsExchange |
|
Line 53... | Line 53... | |||
53 | { |
53 | { |
|
54 | ExchangeBindings = new List<MouseKeyBindingExchange>() |
54 | ExchangeBindings = new List<KeyBindingExchange>() |
|
55 | }; |
55 | }; |
|
56 | |
56 | |
|
57 | RemoteBindingsComboBoxSource = new BindingSource |
57 | RemoteBindingsComboBoxSource = new BindingSource |
|
58 | { |
58 | { |
|
59 | DataSource = MouseKeyBindingsExchange.ExchangeBindings |
59 | DataSource = KeyBindingsExchange.ExchangeBindings |
|
Line 60... | Line 60... | |||
60 | }; |
60 | }; |
|
61 | RemoteBindingsComboBox.DisplayMember = "Nick"; |
61 | RemoteBindingsComboBox.DisplayMember = "Nick"; |
|
62 | RemoteBindingsComboBox.ValueMember = "MouseKeyBindings"; |
62 | RemoteBindingsComboBox.ValueMember = "KeyBindings"; |
|
63 | RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource; |
63 | RemoteBindingsComboBox.DataSource = RemoteBindingsComboBoxSource; |
|
Line 64... | Line 64... | |||
64 | |
64 | |
|
65 | // Start lobby message synchronizer. |
65 | // Start lobby message synchronizer. |
|
66 | LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler, |
66 | LobbyMessageSynchronizer = new LobbyMessageSynchronizer(MqttCommunication, FormTaskScheduler, |
|
67 | FormCancellationTokenSource.Token); |
67 | FormCancellationTokenSource.Token); |
|
Line -... | Line 68... | |||
- | 68 | LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived; |
||
- | 69 | |
||
- | 70 | // Start mouse key bindings synchronizer. |
||
- | 71 | KeyBindingsSynchronizer = new KeyBindingsSynchronizer(LocalKeyBindings, MqttCommunication, |
||
- | 72 | FormTaskScheduler, FormCancellationTokenSource.Token); |
||
68 | LobbyMessageSynchronizer.OnLobbyMessageReceived += OnLobbyMessageReceived; |
73 | KeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; |
|
- | 74 | |
||
- | 75 | // Start mouse key interceptor. |
||
- | 76 | KeyInterceptor = new KeyInterceptor(RemoteKeyBindings, MqttCommunication, FormTaskScheduler, |
||
69 | |
77 | FormCancellationTokenSource.Token); |
|
Line 70... | Line 78... | |||
70 | // Start mouse key bindings synchronizer. |
78 | KeyInterceptor.OnMouseKeyBindingMatched += OnMouseKeyBindingMatched; |
|
Line 71... | Line 79... | |||
71 | MouseKeyBindingsSynchronizer = new MouseKeyBindingsSynchronizer(LocalMouseKeyBindings, MqttCommunication, |
79 | |
|
Line 72... | Line 80... | |||
72 | FormTaskScheduler, FormCancellationTokenSource.Token); |
80 | // Start mouse key simulator. |
|
Line 73... | Line 81... | |||
73 | MouseKeyBindingsSynchronizer.OnMouseKeyBindingsSynchronized += OnMouseKeyBindingsSynchronized; |
81 | KeySimulator = new KeySimulator(LocalKeyBindings, MqttCommunication, FormTaskScheduler, |
|
Line 74... | Line 82... | |||
74 | |
82 | FormCancellationTokenSource.Token); |
|
Line 75... | Line 83... | |||
75 | // Start key binding simulator. |
83 | KeySimulator.OnMouseKeyBindingExecuting += OnMouseKeyBindingExecuting; |
|
Line 76... | Line 84... | |||
76 | } |
84 | } |
|
Line 77... | Line 85... | |||
77 | |
85 | |
|
Line 78... | Line 86... | |||
78 | private static CancellationTokenSource FormCancellationTokenSource { get; set; } |
86 | private static CancellationTokenSource FormCancellationTokenSource { get; set; } |
|
Line 79... | Line 87... | |||
79 | |
87 | |
|
Line 80... | Line 88... | |||
80 | private static TaskScheduler FormTaskScheduler { get; set; } |
88 | private static TaskScheduler FormTaskScheduler { get; set; } |
|
Line 81... | Line 89... | |||
81 | |
89 | |
|
Line 82... | Line -... | |||
82 | private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; } |
- | ||
83 | |
- | ||
84 | private List<string> MouseKeyCombo { get; set; } |
- | ||
85 | |
- | ||
86 | private MouseKeyBindings LocalMouseKeyBindings { get; } |
90 | private static IKeyboardMouseEvents MouseKeyApplicationHook { get; set; } |
|
87 | |
- | ||
88 | private RemoteMouseKeyBindings RemoteMouseKeyBindings { get; } |
- | ||
Line 89... | Line 91... | |||
89 | |
91 | |
|
Line 90... | Line -... | |||
90 | private BindingSource LocalListBoxBindingSource { get; } |
- | ||
91 | |
92 | private List<string> MouseKeyCombo { get; set; } |
|
92 | private BindingSource RemoteBindingsComboBoxSource { get; } |
93 | |
|
93 | |
94 | private LocalKeyBindings LocalKeyBindings { get; } |
|
- | 95 | |
||
94 | private MouseKeyBindingsExchange MouseKeyBindingsExchange { get; } |
96 | private RemoteKeyBindings RemoteKeyBindings { get; } |
|
95 | |
97 | |
|
96 | public MqttCommunication MqttCommunication { get; set; } |
98 | private BindingSource LocalListBoxBindingSource { get; } |
|
- | 99 | |
||
- | 100 | private BindingSource RemoteBindingsComboBoxSource { get; } |
||
- | 101 | |
||
97 | |
102 | private KeyBindingsExchange KeyBindingsExchange { get; } |
|
98 | public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; } |
103 | |
|
99 | |
104 | public MqttCommunication MqttCommunication { get; set; } |
|
100 | public MouseKeyBindingsSynchronizer MouseKeyBindingsSynchronizer { get; set; } |
105 | |
|
- | 106 | public LobbyMessageSynchronizer LobbyMessageSynchronizer { get; set; } |
||
- | 107 | |
||
- | 108 | public KeyBindingsSynchronizer KeyBindingsSynchronizer { get; set; } |
||
- | 109 | |
||
- | 110 | public KeyInterceptor KeyInterceptor { get; set; } |
||
- | 111 | |
||
- | 112 | public KeySimulator KeySimulator { get; set; } |
||
- | 113 | |
||
- | 114 | /// <summary> |
||
- | 115 | /// Clean up any resources being used. |
||
- | 116 | /// </summary> |
||
- | 117 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
||
- | 118 | protected override void Dispose(bool disposing) |
||
- | 119 | { |
||
101 | |
120 | FormCancellationTokenSource?.Dispose(); |
|
Line 102... | Line 121... | |||
102 | private async Task SaveLocalMouseKeyBindings() |
121 | FormCancellationTokenSource = null; |
|
103 | { |
122 | |
|
104 | try |
123 | if (disposing && components != null) |
|
Line 162... | Line 181... | |||
162 | { |
181 | { |
|
163 | ActivityTextBox.AppendText( |
182 | ActivityTextBox.AppendText( |
|
164 | $"{Strings.Client_connection_failed}{Environment.NewLine}"); |
183 | $"{Strings.Client_connection_failed}{Environment.NewLine}"); |
|
165 | } |
184 | } |
|
Line 166... | Line 185... | |||
166 | |
185 | |
|
167 | private void OnMqttServerAuthenticationFailed(object sender, EventArgs e) |
186 | private void OnMqttServerAuthenticationFailed(object sender, MqttAuthenticationFailureEventArgs e) |
|
168 | { |
187 | { |
|
169 | ActivityTextBox.AppendText( |
188 | ActivityTextBox.AppendText( |
|
170 | $"{Strings.Failed_to_authenticate_client}{Environment.NewLine}"); |
189 | $"{Strings.Failed_to_authenticate_client} : {e.Exception}{Environment.NewLine}"); |
|
Line 171... | Line 190... | |||
171 | } |
190 | } |
|
172 | |
191 | |
|
173 | private void OnMqttClientAuthenticationFailed(object sender, EventArgs e) |
192 | private void OnMqttClientAuthenticationFailed(object sender, MqttAuthenticationFailureEventArgs e) |
|
174 | { |
193 | { |
|
175 | ActivityTextBox.AppendText( |
- | ||
176 | $"{Strings.Server_authentication_failed}{Environment.NewLine}"); |
- | ||
177 | } |
- | ||
178 | |
- | ||
179 | /// <summary> |
- | ||
180 | /// Clean up any resources being used. |
- | ||
181 | /// </summary> |
- | ||
182 | /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> |
- | ||
183 | protected override void Dispose(bool disposing) |
- | ||
184 | { |
- | ||
185 | if (disposing && components != null) |
- | ||
186 | { |
- | ||
187 | FormCancellationTokenSource.Dispose(); |
- | ||
188 | FormCancellationTokenSource = null; |
- | ||
189 | |
- | ||
190 | components.Dispose(); |
- | ||
191 | } |
- | ||
192 | |
194 | ActivityTextBox.AppendText( |
|
Line 193... | Line 195... | |||
193 | base.Dispose(disposing); |
195 | $"{Strings.Failed_to_authenticate_with_server} : {e.Exception}{Environment.NewLine}"); |
|
194 | } |
196 | } |
|
195 | |
197 | |
|
196 | private void OnMouseKeyBindingsSynchronized(object sender, MouseKeyBindingsSynchronizedEventArgs e) |
198 | private void OnMouseKeyBindingsSynchronized(object sender, KeyBindingsSynchronizerEventArgs e) |
|
Line 197... | Line 199... | |||
197 | { |
199 | { |
|
198 | ActivityTextBox.AppendText( |
200 | ActivityTextBox.AppendText( |
|
Line 199... | Line 201... | |||
199 | $"{Strings.Synchronized_bindings_with_client} : {e.Bindings.Nick} : {e.Bindings.MouseKeyBindings.Count}{Environment.NewLine}"); |
201 | $"{Strings.Synchronized_bindings_with_client} : {e.Bindings.Nick} : {e.Bindings.KeyBindings.Count}{Environment.NewLine}"); |
|
200 | |
202 | |
|
201 | var exchangeBindings = MouseKeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding => |
203 | var exchangeBindings = KeyBindingsExchange.ExchangeBindings.FirstOrDefault(exchangeBinding => |
|
202 | string.Equals(exchangeBinding.Nick, e.Bindings.Nick, StringComparison.Ordinal)); |
204 | string.Equals(exchangeBinding.Nick, e.Bindings.Nick, StringComparison.Ordinal)); |
|
203 | |
205 | |
|
204 | // If the nick does not exist then add it. |
206 | // If the nick does not exist then add it. |
|
205 | if (exchangeBindings == null) |
207 | if (exchangeBindings == null) |
|
206 | { |
208 | { |
|
Line 207... | Line 209... | |||
207 | MouseKeyBindingsExchange.ExchangeBindings.Add(e.Bindings); |
209 | KeyBindingsExchange.ExchangeBindings.Add(e.Bindings); |
|
208 | RemoteBindingsComboBoxSource.ResetBindings(false); |
210 | RemoteBindingsComboBoxSource.ResetBindings(false); |
|
209 | UpdateRemoteListBoxItems(); |
211 | UpdateRemoteItems(); |
|
210 | return; |
212 | return; |
|
211 | } |
213 | } |
|
212 | |
214 | |
|
213 | // If the bindings for the nick have not changed then do not update. |
215 | // If the bindings for the nick have not changed then do not update. |
|
Line 214... | Line 216... | |||
214 | if (exchangeBindings.MouseKeyBindings.SequenceEqual(e.Bindings.MouseKeyBindings)) |
216 | if (exchangeBindings.KeyBindings.SequenceEqual(e.Bindings.KeyBindings)) |
|
215 | { |
217 | { |
|
216 | RemoteBindingsComboBoxSource.ResetBindings(false); |
218 | RemoteBindingsComboBoxSource.ResetBindings(false); |
|
217 | UpdateRemoteListBoxItems(); |
219 | UpdateRemoteItems(); |
|
218 | return; |
220 | return; |
|
Line 219... | Line 221... | |||
219 | } |
221 | } |
|
220 | |
222 | |
|
221 | // Update the bindings. |
223 | // Update the bindings. |
|
222 | exchangeBindings.MouseKeyBindings = e.Bindings.MouseKeyBindings; |
224 | exchangeBindings.KeyBindings = e.Bindings.KeyBindings; |
|
223 | RemoteBindingsComboBoxSource.ResetBindings(false); |
225 | RemoteBindingsComboBoxSource.ResetBindings(false); |
|
Line -... | Line 226... | |||
- | 226 | UpdateRemoteItems(); |
||
- | 227 | } |
||
- | 228 | |
||
- | 229 | private void UpdateRemoteItems() |
||
- | 230 | { |
||
- | 231 | var exchangeBindings = (List<KeyBinding>) RemoteBindingsComboBox.SelectedValue; |
||
- | 232 | if (exchangeBindings == null) |
||
- | 233 | return; |
||
- | 234 | |
||
- | 235 | var replaceMouseBindings = new List<RemoteKeyBinding>(); |
||
- | 236 | foreach (var remoteBinding in RemoteKeyBindings.Bindings) |
||
- | 237 | { |
||
224 | UpdateRemoteListBoxItems(); |
238 | if (!exchangeBindings.Any(binding => |
|
225 | } |
239 | string.Equals(binding.Name, remoteBinding.Name, StringComparison.Ordinal))) |
|
226 | |
240 | continue; |
|
227 | private void UpdateRemoteListBoxItems() |
241 | |
|
228 | { |
242 | replaceMouseBindings.Add(remoteBinding); |
|
229 | var exchangeBinding = (List<MouseKeyBinding>) RemoteBindingsComboBox.SelectedValue; |
243 | } |
|
Line 230... | Line 244... | |||
230 | if (exchangeBinding == null) |
244 | |
|
231 | return; |
245 | RemoteKeyBindings.Bindings = replaceMouseBindings; |
|
Line 232... | Line 246... | |||
232 | |
246 | |
|
233 | RemoteBindingsListBox.Items.Clear(); |
247 | RemoteBindingsListBox.Items.Clear(); |
|
234 | RemoteBindingsListBox.DisplayMember = "Name"; |
248 | RemoteBindingsListBox.DisplayMember = "Name"; |
|
Line 258... | Line 272... | |||
258 | private async void HostButtonClickAsync(object sender, EventArgs e) |
272 | private async void HostButtonClickAsync(object sender, EventArgs e) |
|
259 | { |
273 | { |
|
260 | // Stop the MQTT server if it is running. |
274 | // Stop the MQTT server if it is running. |
|
261 | if (MqttCommunication.Running) |
275 | if (MqttCommunication.Running) |
|
262 | { |
276 | { |
|
263 | await MqttCommunication.Stop().ConfigureAwait(false); |
277 | await MqttCommunication.Stop(); |
|
264 | HostButton.BackColor = Color.Empty; |
278 | HostButton.BackColor = Color.Empty; |
|
Line 265... | Line 279... | |||
265 | |
279 | |
|
266 | // Enable controls. |
280 | // Enable controls. |
|
267 | ConnectButton.Enabled = true; |
281 | ConnectButton.Enabled = true; |
|
268 | Address.Enabled = true; |
282 | Address.Enabled = true; |
|
269 | Port.Enabled = true; |
283 | Port.Enabled = true; |
|
270 | Nick.Enabled = true; |
- | ||
- | 284 | Nick.Enabled = true; |
||
271 | |
285 | Password.Enabled = true; |
|
272 | return; |
286 | return; |
|
Line 273... | Line 287... | |||
273 | } |
287 | } |
|
274 | |
288 | |
|
Line 275... | Line 289... | |||
275 | if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
289 | if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
|
276 | return; |
290 | return; |
|
277 | |
291 | |
|
278 | // Start the MQTT server. |
292 | // Start the MQTT server. |
|
279 | if (!await MqttCommunication.Start(MqttCommunicationType.Server, ipAddress, port, nick, password) |
293 | if (!await MqttCommunication |
|
280 | .ConfigureAwait(false)) |
294 | .Start(MqttCommunicationType.Server, ipAddress, port, nick, password)) |
|
281 | { |
295 | { |
|
282 | ActivityTextBox.AppendText( |
296 | ActivityTextBox.AppendText( |
|
Line 289... | Line 303... | |||
289 | // Disable controls |
303 | // Disable controls |
|
290 | ConnectButton.Enabled = false; |
304 | ConnectButton.Enabled = false; |
|
291 | Address.Enabled = false; |
305 | Address.Enabled = false; |
|
292 | Port.Enabled = false; |
306 | Port.Enabled = false; |
|
293 | Nick.Enabled = false; |
307 | Nick.Enabled = false; |
|
- | 308 | Password.Enabled = false; |
||
294 | } |
309 | } |
|
Line 295... | Line 310... | |||
295 | |
310 | |
|
296 | private bool ValidateAddressPort(out IPAddress address, out int port, out string nick, out string password) |
311 | private bool ValidateAddressPort(out IPAddress address, out int port, out string nick, out string password) |
|
297 | { |
312 | { |
|
Line 338... | Line 353... | |||
338 | { |
353 | { |
|
339 | Password.BackColor = Color.LightPink; |
354 | Password.BackColor = Color.LightPink; |
|
340 | return false; |
355 | return false; |
|
341 | } |
356 | } |
|
Line 342... | Line 357... | |||
342 | |
357 | |
|
Line 343... | Line 358... | |||
343 | password = AES.LinearFeedbackShiftPassword(Password.Text); |
358 | password = AES.ExpandKey(Password.Text); |
|
344 | |
359 | |
|
345 | Address.BackColor = Color.Empty; |
360 | Address.BackColor = Color.Empty; |
|
346 | Port.BackColor = Color.Empty; |
361 | Port.BackColor = Color.Empty; |
|
Line 352... | Line 367... | |||
352 | |
367 | |
|
353 | private async void ConnectButtonClickAsync(object sender, EventArgs e) |
368 | private async void ConnectButtonClickAsync(object sender, EventArgs e) |
|
354 | { |
369 | { |
|
355 | if (MqttCommunication.Running) |
370 | if (MqttCommunication.Running) |
|
356 | { |
371 | { |
|
357 | await MqttCommunication.Stop().ConfigureAwait(false); |
372 | await MqttCommunication.Stop(); |
|
358 | ConnectButton.Text = Strings.Connect; |
373 | ConnectButton.Text = Strings.Connect; |
|
Line 359... | Line 374... | |||
359 | ConnectButton.BackColor = Color.Empty; |
374 | ConnectButton.BackColor = Color.Empty; |
|
360 | |
375 | |
|
361 | Address.Enabled = true; |
376 | Address.Enabled = true; |
|
- | 377 | Port.Enabled = true; |
||
362 | Port.Enabled = true; |
378 | Nick.Enabled = true; |
|
363 | Nick.Enabled = true; |
379 | Password.Enabled = true; |
|
364 | HostButton.Enabled = true; |
380 | HostButton.Enabled = true; |
|
Line 365... | Line 381... | |||
365 | return; |
381 | return; |
|
366 | } |
382 | } |
|
Line 367... | Line 383... | |||
367 | |
383 | |
|
368 | if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
384 | if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
|
369 | return; |
385 | return; |
|
370 | |
386 | |
|
371 | if (!await MqttCommunication.Start(MqttCommunicationType.Client, ipAddress, port, nick, password) |
387 | if (!await MqttCommunication |
|
372 | .ConfigureAwait(false)) |
388 | .Start(MqttCommunicationType.Client, ipAddress, port, nick, password)) |
|
373 | { |
389 | { |
|
Line 381... | Line 397... | |||
381 | |
397 | |
|
382 | HostButton.Enabled = false; |
398 | HostButton.Enabled = false; |
|
383 | Address.Enabled = false; |
399 | Address.Enabled = false; |
|
384 | Port.Enabled = false; |
400 | Port.Enabled = false; |
|
- | 401 | Nick.Enabled = false; |
||
385 | Nick.Enabled = false; |
402 | Password.Enabled = false; |
|
Line 386... | Line 403... | |||
386 | } |
403 | } |
|
387 | |
404 | |
|
388 | private async void LobbySayTextBoxKeyDown(object sender, KeyEventArgs e) |
405 | private async void LobbySayTextBoxKeyDown(object sender, KeyEventArgs e) |
|
389 | { |
406 | { |
|
Line 390... | Line 407... | |||
390 | if (e.KeyCode != Keys.Enter) |
407 | if (e.KeyCode != Keys.Enter) |
|
Line 391... | Line 408... | |||
391 | return; |
408 | return; |
|
392 | |
409 | |
|
Line 393... | Line 410... | |||
393 | await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false); |
410 | await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text); |
|
394 | |
411 | |
|
395 | LobbySayTextBox.Text = string.Empty; |
412 | LobbySayTextBox.Text = string.Empty; |
|
396 | } |
413 | } |
|
397 | |
414 | |
|
398 | private void HelmAddButtonClick(object sender, EventArgs e) |
415 | private void LocalAddBindingButtonClick(object sender, EventArgs e) |
|
399 | { |
416 | { |
|
Line -... | Line 417... | |||
- | 417 | if (string.IsNullOrEmpty(LocalNameTextBox.Text)) |
||
- | 418 | { |
||
- | 419 | LocalNameTextBox.BackColor = Color.LightPink; |
||
- | 420 | return; |
||
- | 421 | } |
||
- | 422 | |
||
- | 423 | // Only unique names allowed. |
||
- | 424 | if (LocalKeyBindings.Bindings.Any(binding => |
||
- | 425 | string.Equals(binding.Name, LocalNameTextBox.Text, StringComparison.Ordinal))) |
||
- | 426 | { |
||
- | 427 | LocalNameTextBox.BackColor = Color.LightPink; |
||
- | 428 | LocalBindingsListBox.BackColor = Color.LightPink; |
||
400 | if (string.IsNullOrEmpty(LocalNameTextBox.Text)) |
429 | return; |
|
Line 401... | Line 430... | |||
401 | { |
430 | } |
|
Line 402... | Line 431... | |||
402 | LocalNameTextBox.BackColor = Color.LightPink; |
431 | |
|
403 | return; |
- | ||
404 | } |
432 | LocalNameTextBox.BackColor = Color.Empty; |
|
405 | |
433 | LocalBindingsListBox.BackColor = Color.Empty; |
|
406 | ShowOverlayPanel(); |
- | ||
407 | |
434 | |
|
Line 408... | Line 435... | |||
408 | MouseKeyCombo = new List<string>(); |
435 | ShowOverlayPanel(); |
|
409 | |
436 | |
|
410 | MouseKeyApplicationHook = Hook.AppEvents(); |
437 | MouseKeyCombo = new List<string>(); |
|
411 | MouseKeyApplicationHook.MouseDown += LocalMouseKeyHookOnMouseDown; |
438 | |
|
412 | MouseKeyApplicationHook.KeyUp += LocalMouseKeyHookOnKeyUp; |
439 | MouseKeyApplicationHook = Hook.GlobalEvents(); |
|
413 | MouseKeyApplicationHook.KeyDown += LocalMouseKeyHookOnKeyDown; |
440 | MouseKeyApplicationHook.KeyUp += LocalMouseKeyHookOnKeyUp; |
|
Line 414... | Line 441... | |||
414 | MouseKeyApplicationHook.MouseUp += LocalMouseKeyHookOnMouseUp; |
441 | MouseKeyApplicationHook.KeyDown += LocalMouseKeyHookOnKeyDown; |
|
415 | } |
442 | } |
|
416 | |
443 | |
|
Line 417... | Line 444... | |||
417 | private void ShowOverlayPanel() |
444 | private void ShowOverlayPanel() |
|
Line 418... | Line 445... | |||
418 | { |
445 | { |
|
419 | OverlayPanel.BringToFront(); |
446 | OverlayPanel.BringToFront(); |
|
420 | OverlayPanel.Visible = true; |
- | ||
421 | OverlayPanel.Invalidate(); |
- | ||
Line 422... | Line 447... | |||
422 | } |
447 | OverlayPanel.Visible = true; |
|
Line 423... | Line 448... | |||
423 | |
448 | OverlayPanel.Invalidate(); |
|
424 | private async void LocalMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
449 | } |
|
Line 425... | Line 450... | |||
425 | { |
450 | |
|
426 | LocalMouseKeyBindings.Bindings.Add(new MouseKeyBinding(LocalNameTextBox.Text, MouseKeyCombo)); |
451 | private void LocalMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
|
Line 427... | Line 452... | |||
427 | |
452 | { |
|
428 | LocalListBoxBindingSource.ResetBindings(false); |
453 | LocalKeyBindings.Bindings.Add(new KeyBinding(LocalNameTextBox.Text, MouseKeyCombo)); |
|
429 | |
454 | |
|
430 | MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
455 | LocalListBoxBindingSource.ResetBindings(false); |
|
431 | MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
456 | |
|
432 | MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
457 | MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
|
Line 433... | Line -... | |||
433 | MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
- | ||
434 | |
- | ||
435 | MouseKeyApplicationHook.Dispose(); |
- | ||
436 | |
- | ||
437 | LocalNameTextBox.Text = string.Empty; |
- | ||
438 | HideOverlayPanel(); |
- | ||
439 | |
- | ||
440 | await SaveLocalMouseKeyBindings().ConfigureAwait(false); |
- | ||
441 | } |
- | ||
442 | |
- | ||
443 | private void HideOverlayPanel() |
- | ||
444 | { |
- | ||
445 | OverlayPanel.SendToBack(); |
- | ||
446 | OverlayPanel.Visible = false; |
- | ||
447 | OverlayPanel.Invalidate(); |
- | ||
448 | } |
- | ||
449 | |
- | ||
450 | private async void LocalMouseKeyHookOnMouseUp(object sender, MouseEventArgs e) |
- | ||
451 | { |
- | ||
452 | LocalMouseKeyBindings.Bindings.Add(new MouseKeyBinding(LocalNameTextBox.Text, MouseKeyCombo)); |
- | ||
453 | |
- | ||
454 | LocalListBoxBindingSource.ResetBindings(false); |
- | ||
455 | |
- | ||
456 | MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
- | ||
457 | MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
- | ||
458 | MouseKeyApplicationHook.KeyDown -= LocalMouseKeyHookOnKeyDown; |
458 | MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
|
459 | MouseKeyApplicationHook.KeyUp -= LocalMouseKeyHookOnKeyUp; |
459 | |
|
460 | |
460 | MouseKeyApplicationHook.Dispose(); |
|
Line -... | Line 461... | |||
- | 461 | |
||
- | 462 | LocalNameTextBox.Text = string.Empty; |
||
461 | MouseKeyApplicationHook.Dispose(); |
463 | HideOverlayPanel(); |
|
462 | |
464 | |
|
Line 463... | Line 465... | |||
463 | LocalNameTextBox.Text = string.Empty; |
465 | //await SaveLocalMouseKeyBindings(); |
|
464 | HideOverlayPanel(); |
466 | } |
|
465 | |
467 | |
|
466 | await SaveLocalMouseKeyBindings().ConfigureAwait(false); |
468 | private void HideOverlayPanel() |
|
Line 467... | Line 469... | |||
467 | } |
469 | { |
|
468 | |
470 | OverlayPanel.SendToBack(); |
|
469 | |
471 | OverlayPanel.Visible = false; |
|
470 | private void LocalMouseKeyHookOnMouseDown(object sender, MouseEventArgs e) |
472 | OverlayPanel.Invalidate(); |
|
471 | { |
473 | } |
|
Line 472... | Line 474... | |||
472 | MouseKeyCombo.Add(e.Button.ToDisplayName()); |
474 | |
|
473 | } |
475 | private void LocalMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
|
Line 474... | Line 476... | |||
474 | |
476 | { |
|
475 | private void LocalMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
477 | e.SuppressKeyPress = true; |
|
Line 476... | Line 478... | |||
476 | { |
478 | |
|
477 | e.SuppressKeyPress = true; |
479 | KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key); |
|
478 | |
480 | |
|
Line 479... | Line 481... | |||
479 | MouseKeyCombo.Add(e.KeyCode.ToDisplayName()); |
481 | MouseKeyCombo.Add(key); |
|
480 | } |
482 | } |
|
Line 481... | Line 483... | |||
481 | |
483 | |
|
482 | private void HelmNameTextBoxClick(object sender, EventArgs e) |
484 | private void LocalNameTextBoxClick(object sender, EventArgs e) |
|
483 | { |
485 | { |
|
484 | LocalNameTextBox.BackColor = Color.Empty; |
486 | LocalNameTextBox.BackColor = Color.Empty; |
|
Line 485... | Line 487... | |||
485 | } |
487 | } |
|
486 | |
488 | |
|
487 | private async void HelmRemoveButtonClick(object sender, EventArgs e) |
489 | private void LocalBindingsRemoveButtonClick(object sender, EventArgs e) |
|
- | 490 | { |
||
488 | { |
491 | var helmBinding = (KeyBinding) LocalBindingsListBox.SelectedItem; |
|
489 | var helmBinding = (MouseKeyBinding) LocalBindingsListBox.SelectedItem; |
492 | if (helmBinding == null) |
|
Line 490... | Line 493... | |||
490 | if (helmBinding == null) |
493 | return; |
|
491 | return; |
494 | |
|
492 | |
495 | LocalKeyBindings.Bindings.Remove(helmBinding); |
|
493 | LocalMouseKeyBindings.Bindings.Remove(helmBinding); |
496 | LocalListBoxBindingSource.ResetBindings(false); |
|
494 | LocalListBoxBindingSource.ResetBindings(false); |
497 | |
|
495 | |
498 | // await SaveLocalMouseKeyBindings(); |
|
496 | await SaveLocalMouseKeyBindings().ConfigureAwait(false); |
- | ||
497 | } |
499 | } |
|
498 | |
- | ||
Line 499... | Line 500... | |||
499 | private async void LobbySayButtonClick(object sender, EventArgs e) |
500 | |
|
Line 500... | Line 501... | |||
500 | { |
501 | private async void LobbySayButtonClick(object sender, EventArgs e) |
|
501 | await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text).ConfigureAwait(false); |
- | ||
Line 502... | Line 502... | |||
502 | |
502 | { |
|
Line 503... | Line 503... | |||
503 | LobbySayTextBox.Text = string.Empty; |
503 | await LobbyMessageSynchronizer.Broadcast(LobbySayTextBox.Text); |
|
504 | } |
- | ||
505 | |
- | ||
506 | private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) |
- | ||
507 | { |
- | ||
508 | UpdateRemoteListBoxItems(); |
- | ||
509 | } |
504 | |
|
510 | |
505 | LobbySayTextBox.Text = string.Empty; |
|
511 | private async void WingManFormOnLoad(object sender, EventArgs e) |
- | ||
512 | { |
506 | } |
|
Line 513... | Line 507... | |||
513 | await LoadLocalMouseKeyBindings(); |
507 | |
|
514 | await LoadRemoteMouseKeyBindings(); |
508 | private void RemoteBindingsComboBoxSelectionChangeCompleted(object sender, EventArgs e) |
|
- | 509 | { |
||
- | 510 | UpdateRemoteItems(); |
||
- | 511 | } |
||
- | 512 | |
||
515 | } |
513 | private void WingManFormOnLoad(object sender, EventArgs e) |
|
- | 514 | { |
||
Line 516... | Line 515... | |||
516 | |
515 | // await LoadLocalMouseKeyBindings(); |
|
Line 517... | Line 516... | |||
517 | private async Task LoadLocalMouseKeyBindings() |
516 | |
|
518 | { |
517 | // await LoadRemoteMouseKeyBindings(); |
|
- | 518 | } |
||
519 | try |
519 | |
|
- | 520 | private void RemoteBindingsBindButtonClicked(object sender, EventArgs e) |
||
- | 521 | { |
||
520 | { |
522 | if (string.IsNullOrEmpty((string) RemoteBindingsListBox.SelectedItem)) |
|
521 | using (var fileStream = new FileStream("LocalMouseKeyBindings.xml", FileMode.Open)) |
523 | { |
|
522 | { |
524 | RemoteBindingsListBox.BackColor = Color.LightPink; |
|
Line 523... | Line 525... | |||
523 | using (var memoryStream = new MemoryStream()) |
525 | return; |
|
524 | { |
526 | } |
|
525 | await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false); |
527 | |
|
Line 526... | Line 528... | |||
526 | |
528 | RemoteBindingsListBox.BackColor = Color.Empty; |
|
527 | memoryStream.Position = 0L; |
- | ||
Line 528... | Line -... | |||
528 | |
- | ||
529 | var loadedBindings = |
- | ||
530 | (MouseKeyBindings) MouseKeyBindings.XmlSerializer.Deserialize(memoryStream); |
529 | |
|
531 | |
530 | ShowOverlayPanel(); |
|
Line 532... | Line 531... | |||
532 | foreach (var binding in loadedBindings.Bindings) LocalMouseKeyBindings.Bindings.Add(binding); |
531 | |
|
533 | |
532 | MouseKeyCombo = new List<string>(); |
|
534 | LocalListBoxBindingSource.ResetBindings(false); |
533 | |
|
535 | } |
534 | MouseKeyApplicationHook = Hook.GlobalEvents(); |
|
Line 536... | Line 535... | |||
536 | } |
535 | MouseKeyApplicationHook.KeyUp += RemoteMouseKeyHookOnKeyUp; |
|
537 | } |
536 | MouseKeyApplicationHook.KeyDown += RemoteMouseKeyHookOnKeyDown; |
|
538 | catch (Exception) |
- | ||
539 | { |
- | ||
Line 540... | Line 537... | |||
540 | ActivityTextBox.AppendText( |
537 | } |
|
Line 541... | Line 538... | |||
541 | $"{Strings.Failed_loading_local_bindings}{Environment.NewLine}"); |
538 | |
|
542 | } |
539 | private void RemoteBindingsUnbindButtonClicked(object sender, EventArgs e) |
|
Line 543... | Line 540... | |||
543 | } |
540 | { |
|
544 | |
541 | var item = (string) RemoteBindingsListBox.SelectedItem; |
|
Line 545... | Line 542... | |||
545 | private void RemoteBindingsBindButtonClicked(object sender, EventArgs e) |
542 | if (string.IsNullOrEmpty(item)) |
|
546 | { |
543 | { |
|
547 | ShowOverlayPanel(); |
- | ||
548 | |
544 | RemoteBindingsListBox.BackColor = Color.LightPink; |
|
Line 549... | Line 545... | |||
549 | MouseKeyCombo = new List<string>(); |
545 | return; |
|
550 | |
546 | } |
|
551 | MouseKeyApplicationHook = Hook.AppEvents(); |
- | ||
552 | MouseKeyApplicationHook.MouseDown += RemoteMouseKeyHookOnMouseDown; |
547 | |
|
Line -... | Line 548... | |||
- | 548 | RemoteBindingsListBox.BackColor = Color.Empty; |
||
- | 549 | |
||
- | 550 | var remoteKeyBinding = RemoteKeyBindings.Bindings.FirstOrDefault(binding => |
||
553 | MouseKeyApplicationHook.KeyUp += RemoteMouseKeyHookOnKeyUp; |
551 | string.Equals(binding.Name, item, StringComparison.Ordinal)); |
|
Line 554... | Line 552... | |||
554 | MouseKeyApplicationHook.KeyDown += RemoteMouseKeyHookOnKeyDown; |
552 | |
|
555 | MouseKeyApplicationHook.MouseUp += RemoteMouseKeyHookOnMouseUp; |
553 | if (remoteKeyBinding == null) |
|
- | 554 | return; |
||
- | 555 | |
||
- | 556 | RemoteKeyBindings.Bindings.Remove(remoteKeyBinding); |
||
- | 557 | RemoteBindingsBindToBox.Text = string.Empty; |
||
- | 558 | } |
||
- | 559 | |
||
- | 560 | private void RemoteMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
||
- | 561 | { |
||
- | 562 | e.SuppressKeyPress = true; |
||
- | 563 | |
||
- | 564 | KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key); |
||
- | 565 | |
||
Line -... | Line 566... | |||
- | 566 | MouseKeyCombo.Add(key); |
||
- | 567 | } |
||
- | 568 | |
||
- | 569 | private void RemoteMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
||
- | 570 | { |
||
- | 571 | RemoteKeyBindings.Bindings.Add(new RemoteKeyBinding(RemoteBindingsComboBox.Text, |
||
- | 572 | (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); |
||
- | 573 | |
||
- | 574 | MouseKeyApplicationHook.KeyDown -= RemoteMouseKeyHookOnKeyDown; |
||
- | 575 | MouseKeyApplicationHook.KeyUp -= RemoteMouseKeyHookOnKeyUp; |
||
- | 576 | |
||
- | 577 | MouseKeyApplicationHook.Dispose(); |
||
- | 578 | |
||
- | 579 | RemoteBindingsBindToBox.Text = string.Join(" + ", MouseKeyCombo); |
||
- | 580 | HideOverlayPanel(); |
||
- | 581 | |
||
- | 582 | // await SaveRemoteMouseKeyBindings(); |
||
- | 583 | } |
||
- | 584 | |
||
- | 585 | private void RemoteBindingsListBoxSelectedValueChanged(object sender, EventArgs e) |
||
- | 586 | { |
||
- | 587 | RemoteBindingsBindToBox.Text = ""; |
||
- | 588 | |
||
- | 589 | var name = (string) RemoteBindingsListBox.SelectedItem; |
||
- | 590 | if (string.IsNullOrEmpty(name)) |
||
- | 591 | return; |
||
- | 592 | |
||
- | 593 | foreach (var binding in RemoteKeyBindings.Bindings) |
||
- | 594 | { |
||
- | 595 | if (!string.Equals(binding.Name, name)) |
||
- | 596 | continue; |
||
- | 597 | |
||
556 | } |
598 | RemoteBindingsBindToBox.Text = string.Join(" + ", binding.Keys); |
|
- | 599 | break; |
||
- | 600 | } |
||
- | 601 | } |
||
- | 602 | |
||
- | 603 | #region Saving and loading |
||
- | 604 | |
||
- | 605 | private async Task SaveLocalMouseKeyBindings() |
||
- | 606 | { |
||
557 | |
607 | try |
|
Line 558... | Line 608... | |||
558 | private void RemoteMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
608 | { |
|
559 | { |
609 | using (var memoryStream = new MemoryStream()) |
|
560 | e.SuppressKeyPress = true; |
610 | { |
|
561 | |
611 | LocalKeyBindings.XmlSerializer.Serialize(memoryStream, LocalKeyBindings); |
|
562 | MouseKeyCombo.Add(e.KeyCode.ToDisplayName()); |
612 | |
|
563 | } |
613 | memoryStream.Position = 0L; |
|
564 | |
614 | |
|
Line 565... | Line 615... | |||
565 | private void RemoteMouseKeyHookOnMouseDown(object sender, MouseEventArgs e) |
615 | using (var fileStream = new FileStream("LocalKeyBindings.xml", FileMode.Create)) |
|
Line 566... | Line 616... | |||
566 | { |
616 | { |
|
567 | MouseKeyCombo.Add(e.Button.ToDisplayName()); |
617 | await memoryStream.CopyToAsync(fileStream); |
|
568 | } |
618 | } |
|
569 | |
619 | } |
|
570 | private async void RemoteMouseKeyHookOnMouseUp(object sender, MouseEventArgs e) |
620 | } |
|
571 | { |
621 | catch (Exception) |
|
572 | RemoteMouseKeyBindings.Bindings.Add(new RemoteMouseKeyBinding(RemoteBindingsComboBox.Text, |
622 | { |
|
573 | (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); |
623 | ActivityTextBox.AppendText( |
|
Line 628... | Line 678... | |||
628 | |
678 | |
|
629 | private async Task LoadRemoteMouseKeyBindings() |
679 | private async Task LoadRemoteMouseKeyBindings() |
|
630 | { |
680 | { |
|
631 | try |
681 | try |
|
632 | { |
682 | { |
|
633 | using (var fileStream = new FileStream("RemoteMouseKeyBindings.xml", FileMode.Open)) |
683 | using (var fileStream = new FileStream("RemoteKeyBindings.xml", FileMode.Open)) |
|
634 | { |
684 | { |
|
635 | using (var memoryStream = new MemoryStream()) |
685 | using (var memoryStream = new MemoryStream()) |
|
636 | { |
686 | { |
|
Line 637... | Line 687... | |||
637 | await fileStream.CopyToAsync(memoryStream).ConfigureAwait(false); |
687 | await fileStream.CopyToAsync(memoryStream); |
|
Line 638... | Line 688... | |||
638 | |
688 | |
|
639 | memoryStream.Position = 0L; |
689 | memoryStream.Position = 0L; |
|
Line 640... | Line 690... | |||
640 | |
690 | |
|
641 | var loadedBindings = |
691 | var loadedBindings = |
|
642 | (RemoteMouseKeyBindings) RemoteMouseKeyBindings.XmlSerializer.Deserialize(memoryStream); |
692 | (RemoteKeyBindings) RemoteKeyBindings.XmlSerializer.Deserialize(memoryStream); |
|
643 | |
693 | |
|
644 | foreach (var binding in loadedBindings.Bindings) RemoteMouseKeyBindings.Bindings.Add(binding); |
694 | foreach (var binding in loadedBindings.Bindings) RemoteKeyBindings.Bindings.Add(binding); |
|
645 | } |
695 | } |
|
646 | } |
696 | } |
|
647 | } |
697 | } |
|
648 | catch (Exception) |
698 | catch (Exception) |
|
649 | { |
699 | { |
|
- | 700 | ActivityTextBox.AppendText( |
||
- | 701 | $"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}"); |
||
650 | ActivityTextBox.AppendText( |
702 | } |
|
651 | $"{Strings.Failed_loading_remote_bindings}{Environment.NewLine}"); |
703 | } |