WingMan – Diff between revs 14 and 21
?pathlinks?
Rev 14 | Rev 21 | |||
---|---|---|---|---|
Line 110... | Line 110... | |||
110 | |
110 | |
|
Line 111... | Line 111... | |||
111 | public KeyInterceptor KeyInterceptor { get; set; } |
111 | public KeyInterceptor KeyInterceptor { get; set; } |
|
Line -... | Line 112... | |||
- | 112 | |
||
112 | |
113 | public KeySimulator KeySimulator { get; set; } |
|
113 | public KeySimulator KeySimulator { get; set; } |
114 | |
|
114 | |
115 | /// <inheritdoc /> |
|
115 | /// <summary> |
116 | /// <summary> |
|
116 | /// Clean up any resources being used. |
117 | /// Clean up any resources being used. |
|
Line 241... | Line 242... | |||
241 | continue; |
242 | continue; |
|
Line 242... | Line 243... | |||
242 | |
243 | |
|
243 | replaceMouseBindings.Add(remoteBinding); |
244 | replaceMouseBindings.Add(remoteBinding); |
|
Line 244... | Line 245... | |||
244 | } |
245 | } |
|
- | 246 | |
||
Line 245... | Line 247... | |||
245 | |
247 | RemoteKeyBindings.Bindings.Clear(); |
|
246 | RemoteKeyBindings.Bindings = replaceMouseBindings; |
248 | foreach (var binding in replaceMouseBindings) RemoteKeyBindings.Bindings.Add(binding); |
|
247 | |
249 | |
|
248 | RemoteBindingsListBox.Items.Clear(); |
250 | RemoteBindingsListBox.Items.Clear(); |
|
Line 285... | Line 287... | |||
285 | Nick.Enabled = true; |
287 | Nick.Enabled = true; |
|
286 | Password.Enabled = true; |
288 | Password.Enabled = true; |
|
287 | return; |
289 | return; |
|
288 | } |
290 | } |
|
Line 289... | Line 291... | |||
289 | |
291 | |
|
290 | if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
292 | if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) |
|
Line 291... | Line 293... | |||
291 | return; |
293 | return; |
|
292 | |
294 | |
|
293 | // Start the MQTT server. |
295 | // Start the MQTT server. |
|
Line 307... | Line 309... | |||
307 | Port.Enabled = false; |
309 | Port.Enabled = false; |
|
308 | Nick.Enabled = false; |
310 | Nick.Enabled = false; |
|
309 | Password.Enabled = false; |
311 | Password.Enabled = false; |
|
310 | } |
312 | } |
|
Line 311... | Line 313... | |||
311 | |
313 | |
|
- | 314 | private bool ValidateConnectionParameters( |
||
- | 315 | out IPAddress address, |
||
- | 316 | out int port, |
||
- | 317 | out string nick, |
||
312 | private bool ValidateAddressPort(out IPAddress address, out int port, out string nick, out string password) |
318 | out string password) |
|
313 | { |
319 | { |
|
314 | address = IPAddress.Any; |
320 | address = IPAddress.Any; |
|
315 | port = 0; |
321 | port = 0; |
|
316 | nick = string.Empty; |
322 | nick = string.Empty; |
|
Line 327... | Line 333... | |||
327 | Password.BackColor = Color.LightPink; |
333 | Password.BackColor = Color.LightPink; |
|
328 | return false; |
334 | return false; |
|
329 | } |
335 | } |
|
Line 330... | Line 336... | |||
330 | |
336 | |
|
- | 337 | if (!IPAddress.TryParse(Address.Text, out address)) |
||
- | 338 | try |
||
- | 339 | { |
||
- | 340 | address = Dns.GetHostAddresses(Address.Text).FirstOrDefault(); |
||
- | 341 | } |
||
331 | if (!IPAddress.TryParse(Address.Text, out address)) |
342 | catch (Exception ex) |
|
- | 343 | { |
||
- | 344 | ActivityTextBox.AppendText( |
||
- | 345 | $"{Strings.Could_not_resolve_hostname} : {ex.Message}{Environment.NewLine}"); |
||
332 | { |
346 | |
|
333 | Address.BackColor = Color.LightPink; |
347 | Address.BackColor = Color.LightPink; |
|
334 | return false; |
348 | return false; |
|
Line 335... | Line 349... | |||
335 | } |
349 | } |
|
Line 380... | Line 394... | |||
380 | Password.Enabled = true; |
394 | Password.Enabled = true; |
|
381 | HostButton.Enabled = true; |
395 | HostButton.Enabled = true; |
|
382 | return; |
396 | return; |
|
383 | } |
397 | } |
|
Line 384... | Line 398... | |||
384 | |
398 | |
|
385 | if (!ValidateAddressPort(out var ipAddress, out var port, out var nick, out var password)) |
399 | if (!ValidateConnectionParameters(out var ipAddress, out var port, out var nick, out var password)) |
|
Line 386... | Line 400... | |||
386 | return; |
400 | return; |
|
387 | |
401 | |
|
388 | if (!await MqttCommunication |
402 | if (!await MqttCommunication |
|
Line 531... | Line 545... | |||
531 | ShowOverlayPanel(); |
545 | ShowOverlayPanel(); |
|
Line 532... | Line 546... | |||
532 | |
546 | |
|
Line 533... | Line 547... | |||
533 | MouseKeyCombo = new List<string>(); |
547 | MouseKeyCombo = new List<string>(); |
|
534 | |
548 | |
|
535 | MouseKeyApplicationHook = Hook.GlobalEvents(); |
549 | MouseKeyApplicationHook = Hook.GlobalEvents(); |
|
536 | MouseKeyApplicationHook.KeyUp += RemoteMouseKeyHookOnKeyUp; |
550 | MouseKeyApplicationHook.KeyUp += RemoteKeyHookOnKeyUp; |
|
Line 537... | Line 551... | |||
537 | MouseKeyApplicationHook.KeyDown += RemoteMouseKeyHookOnKeyDown; |
551 | MouseKeyApplicationHook.KeyDown += RemoteKeyHookOnKeyDown; |
|
538 | } |
552 | } |
|
539 | |
553 | |
|
Line 556... | Line 570... | |||
556 | |
570 | |
|
557 | RemoteKeyBindings.Bindings.Remove(remoteKeyBinding); |
571 | RemoteKeyBindings.Bindings.Remove(remoteKeyBinding); |
|
558 | RemoteBindingsBindToBox.Text = string.Empty; |
572 | RemoteBindingsBindToBox.Text = string.Empty; |
|
Line 559... | Line 573... | |||
559 | } |
573 | } |
|
560 | |
574 | |
|
561 | private void RemoteMouseKeyHookOnKeyDown(object sender, KeyEventArgs e) |
575 | private void RemoteKeyHookOnKeyDown(object sender, KeyEventArgs e) |
|
Line 562... | Line 576... | |||
562 | { |
576 | { |
|
- | 577 | e.SuppressKeyPress = true; |
||
Line 563... | Line 578... | |||
563 | e.SuppressKeyPress = true; |
578 | |
|
564 | |
579 | if (!KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key)) |
|
Line 565... | Line 580... | |||
565 | KeyConversion.KeysToString.TryGetValue((byte) e.KeyCode, out var key); |
580 | return; |
|
566 | |
581 | |
|
567 | MouseKeyCombo.Add(key); |
582 | MouseKeyCombo.Add(key); |
|
568 | } |
583 | } |
|
Line 569... | Line 584... | |||
569 | |
584 | |
|
570 | private async void RemoteMouseKeyHookOnKeyUp(object sender, KeyEventArgs e) |
585 | private async void RemoteKeyHookOnKeyUp(object sender, KeyEventArgs e) |
|
Line 571... | Line 586... | |||
571 | { |
586 | { |
|
Line 572... | Line 587... | |||
572 | RemoteKeyBindings.Bindings.Add(new RemoteKeyBinding(RemoteBindingsComboBox.Text, |
587 | RemoteKeyBindings.Bindings.Add(new RemoteKeyBinding(RemoteBindingsComboBox.Text, |
|
573 | (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); |
588 | (string) RemoteBindingsListBox.SelectedItem, MouseKeyCombo)); |
|
Line 643... | Line 658... | |||
643 | memoryStream.Position = 0L; |
658 | memoryStream.Position = 0L; |
|
Line 644... | Line 659... | |||
644 | |
659 | |
|
645 | var loadedBindings = |
660 | var loadedBindings = |
|
Line 646... | Line 661... | |||
646 | (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(memoryStream); |
661 | (LocalKeyBindings) LocalKeyBindings.XmlSerializer.Deserialize(memoryStream); |
|
- | 662 | |
||
Line 647... | Line 663... | |||
647 | |
663 | foreach (var binding in loadedBindings.Bindings) |
|
648 | foreach (var binding in loadedBindings.Bindings) LocalKeyBindings.Bindings.Add(binding); |
664 | LocalKeyBindings.Bindings.Add(binding); |
|
649 | |
665 | |
|
650 | LocalListBoxBindingSource.ResetBindings(false); |
666 | LocalListBoxBindingSource.ResetBindings(false); |
|
Line 694... | Line 710... | |||
694 | memoryStream.Position = 0L; |
710 | memoryStream.Position = 0L; |
|
Line 695... | Line 711... | |||
695 | |
711 | |
|
696 | var loadedBindings = |
712 | var loadedBindings = |
|
Line 697... | Line 713... | |||
697 | (RemoteKeyBindings) RemoteKeyBindings.XmlSerializer.Deserialize(memoryStream); |
713 | (RemoteKeyBindings) RemoteKeyBindings.XmlSerializer.Deserialize(memoryStream); |
|
- | 714 | |
||
698 | |
715 | foreach (var binding in loadedBindings.Bindings) |
|
699 | foreach (var binding in loadedBindings.Bindings) RemoteKeyBindings.Bindings.Add(binding); |
716 | RemoteKeyBindings.Bindings.Add(binding); |
|
700 | } |
717 | } |
|
701 | } |
718 | } |
|
702 | } |
719 | } |