From 0c39457e61d2533dab1744d9c8a92eac6c89ea3c Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 18:33:29 -0400 Subject: [PATCH 01/25] Update Settings1.xaml --- KeyNStroke/Settings1.xaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/KeyNStroke/Settings1.xaml b/KeyNStroke/Settings1.xaml index e8f3203..ec426f9 100644 --- a/KeyNStroke/Settings1.xaml +++ b/KeyNStroke/Settings1.xaml @@ -64,6 +64,8 @@ Margin="5"> Show Keystroke History + Label follows cursor position Date: Sat, 26 Feb 2022 18:35:06 -0400 Subject: [PATCH 02/25] Update SettingsStore.cs --- KeyNStroke/SettingsStore.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/KeyNStroke/SettingsStore.cs b/KeyNStroke/SettingsStore.cs index 2806053..44b295b 100644 --- a/KeyNStroke/SettingsStore.cs +++ b/KeyNStroke/SettingsStore.cs @@ -1,4 +1,4 @@ -using Microsoft.Win32; +using Microsoft.Win32; using System; using System.Collections.Generic; using System.ComponentModel; @@ -203,6 +203,7 @@ class Settings [DataMember] public Nullable enableHistoryTimeout = null; [DataMember] public Nullable enableWindowFade = null; [DataMember] public Nullable enableCursorIndicator = null; + [DataMember] public Nullable enableCursorFollow = null; [DataMember] public Nullable cursorIndicatorOpacity = null; [DataMember] public Nullable cursorIndicatorSize = null; [DataMember] public SerializableColor2 cursorIndicatorColor = null; @@ -416,6 +417,13 @@ public bool EnableCursorIndicator set { i.enableCursorIndicator = value; OnSettingChanged("EnableCursorIndicator"); } } + public bool EnableCursorFollowDefault = false; + public bool EnableCursorFollow + { + get { return Or(i.enableCursorFollow, EnableCursorFollowDefault); } + set { i.enableCursorFollow = value; OnSettingChanged("EnableCursorFollow"); } + } + public double CursorIndicatorOpacityDefault = 0.3; public double CursorIndicatorOpacity { @@ -694,6 +702,7 @@ public void CallPropertyChangedForAllProperties() PropertyChanged(this, new PropertyChangedEventArgs("EnableHistoryTimeout")); PropertyChanged(this, new PropertyChangedEventArgs("EnableWindowFade")); PropertyChanged(this, new PropertyChangedEventArgs("EnableCursorIndicator")); + PropertyChanged(this, new PropertyChangedEventArgs("EnableCursorFollow")); PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorOpacity")); PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorSize")); PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorColor")); @@ -827,6 +836,7 @@ public override string ToString() EnableHistoryTimeout: {EnableHistoryTimeout} EnableWindowFade: {EnableWindowFade} EnableCursorIndicator: {EnableCursorIndicator} +EnableCursorFollow: {EnableCursorFollow} CursorIndicatorOpacity: {CursorIndicatorOpacity} CursorIndicatorSize: {CursorIndicatorSize} CursorIndicatorColor: {CursorIndicatorColor} From d25319ec83a7b8a1b113b7f6faa7cdaf633265d7 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 18:40:32 -0400 Subject: [PATCH 03/25] Update KeystrokeDisplay.xaml.cs --- KeyNStroke/KeystrokeDisplay.xaml.cs | 60 +++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/KeyNStroke/KeystrokeDisplay.xaml.cs b/KeyNStroke/KeystrokeDisplay.xaml.cs index d08ed68..3963258 100644 --- a/KeyNStroke/KeystrokeDisplay.xaml.cs +++ b/KeyNStroke/KeystrokeDisplay.xaml.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; @@ -29,24 +29,37 @@ public partial class KeystrokeDisplay : Window { readonly SettingsStore settings; readonly IKeystrokeEventProvider k; + IMouseRawEventProvider m = null; IntPtr windowHandle; Brush OrigInnerPanelBackgroundColor; - public KeystrokeDisplay(IKeystrokeEventProvider k, SettingsStore s) + public KeystrokeDisplay(IMouseRawEventProvider m, IKeystrokeEventProvider k, SettingsStore s) { - InitializeComponent(); - InitializeAnimations(); - + this.m = m; this.k = k; + this.settings = s; + initializeDisplay(); + } + public KeystrokeDisplay(IKeystrokeEventProvider k, SettingsStore s) + { + this.k = k; this.settings = s; + initializeDisplay(); + } + + private void initializeDisplay() + { + InitializeComponent(); + InitializeAnimations(); + this.settings.EnableSettingsMode = false; this.settings.EnablePasswordMode = false; this.settings.PropertyChanged += SettingChanged; this.settings.CallPropertyChangedForAllProperties(); - this.buttonResizeWindow.Settings = s; - this.buttonResizeInnerPanel.Settings = s; + this.buttonResizeWindow.Settings = this.settings; + this.buttonResizeInnerPanel.Settings = this.settings; //addWelcomeInfo(); } @@ -57,6 +70,12 @@ private void Window_Loaded(object sender, RoutedEventArgs e) InitPeriodicTopmostTimer(); windowHandle = new WindowInteropHelper(this).Handle; + if (this.m != null) + { + this.m.MouseEvent += m_MouseEvent; + SetFormStyles(); + } + this.k.KeystrokeEvent += KeystrokeEvent; OrigInnerPanelBackgroundColor = innerPanel.Background; @@ -69,6 +88,33 @@ private void Window_Loaded(object sender, RoutedEventArgs e) } } + void m_MouseEvent(MouseRawEventArgs raw_e) + { + if (raw_e.Action == MouseAction.Move) + { + UpdatePosition(raw_e.Position); + } + } + + void UpdatePosition(NativeMethodsMouse.POINT cursorPosition) + { + IntPtr monitor = NativeMethodsWindow.MonitorFromPoint(cursorPosition, NativeMethodsWindow.MonitorOptions.MONITOR_DEFAULTTONEAREST); + uint adpiX = 0, adpiY = 0; + NativeMethodsWindow.GetDpiForMonitor(monitor, NativeMethodsWindow.DpiType.MDT_EFFECTIVE_DPI, ref adpiX, ref adpiY); + Log.e("CI", $"apix={adpiX} adpiy={adpiY} aw={ActualWidth} ah={ActualHeight} cx={cursorPosition.X} cy={cursorPosition.Y}"); + NativeMethodsWindow.SetWindowPosition(windowHandle, + (int)((cursorPosition.X + 82) * (double)adpiX / 96.0), + (int)((cursorPosition.Y + 82) * (double)adpiY / 96.0)); + } + + void SetFormStyles() + { + Log.e("CI", $"WindowHandle={windowHandle}"); + NativeMethodsGWL.ClickThrough(windowHandle); + NativeMethodsGWL.HideFromAltTab(windowHandle); + UpdatePosition(NativeMethodsMouse.CursorPosition); + } + #region periodically make TopMost readonly DispatcherTimer makeTopMostTimer = new DispatcherTimer(); void InitPeriodicTopmostTimer() From 638f3936c529b53cc3d25adafcb5c87cbf00a9c0 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 18:47:17 -0400 Subject: [PATCH 04/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index c14d6cd..26d3c23 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -39,6 +39,8 @@ public static void Main() SettingsStore mySettings; Window welcomeWindow; Settings1 settingsWindow; + KeystrokeDisplay KeystrokeHistoryWindow = null; + bool KeystrokeHistoryVisible = false; protected override void OnStartup(StartupEventArgs e) { @@ -231,6 +233,13 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) case "EnableKeystrokeHistory": OnKeystrokeHistorySettingChanged(); break; + case "EnableCursorFollow": + if (KeystrokeHistoryVisible) + { + DisableKeystrokeHistory(); + OnKeystrokeHistorySettingChanged(); + } + break; case "EnableAnnotateLine": OnAnnotateLineSettingChanged(); break; @@ -260,9 +269,6 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) #region Keystroke History - KeystrokeDisplay KeystrokeHistoryWindow; - bool KeystrokeHistoryVisible; - private void OnKeystrokeHistorySettingChanged() { if (mySettings.EnableKeystrokeHistory && !mySettings.Standby) From 59254c29bed5fd9d8eef1c1e0b24c14b65a9568c Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 18:52:51 -0400 Subject: [PATCH 05/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 26d3c23..c363a50 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -234,10 +234,10 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - if (KeystrokeHistoryVisible) + if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { DisableKeystrokeHistory(); - OnKeystrokeHistorySettingChanged(); + //OnKeystrokeHistorySettingChanged(); } break; case "EnableAnnotateLine": From efaa50d937e4f768aa125257dce2f851149f4dfa Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 18:57:02 -0400 Subject: [PATCH 06/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index c363a50..e660f26 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -234,11 +234,11 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) - { - DisableKeystrokeHistory(); + //if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) + //{ + // DisableKeystrokeHistory(); //OnKeystrokeHistorySettingChanged(); - } + //} break; case "EnableAnnotateLine": OnAnnotateLineSettingChanged(); From 6a17c074e2d3c8cff60f9072e5734b3ef95b9122 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:04:46 -0400 Subject: [PATCH 07/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index e660f26..9c49be9 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -234,11 +234,11 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - //if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) - //{ + if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) + { // DisableKeystrokeHistory(); //OnKeystrokeHistorySettingChanged(); - //} + } break; case "EnableAnnotateLine": OnAnnotateLineSettingChanged(); From e589f17a13fc173a00afe22d8927ac97ea775eb8 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:12:52 -0400 Subject: [PATCH 08/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 9c49be9..b0884af 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -234,10 +234,13 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) + if (mySettings.EnableCursorFollow) { - // DisableKeystrokeHistory(); - //OnKeystrokeHistorySettingChanged(); + if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) + { + DisableKeystrokeHistory(); + OnKeystrokeHistorySettingChanged(); + } } break; case "EnableAnnotateLine": From 9bf8e1234555f9e54a5a4a84ecd182511296fc54 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:18:50 -0400 Subject: [PATCH 09/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index b0884af..1340e21 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -239,7 +239,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { DisableKeystrokeHistory(); - OnKeystrokeHistorySettingChanged(); + Task.Delay(1000).ContinueWith(t=> OnKeystrokeHistorySettingChanged()) } } break; From 2f84ff6fb478265d3c8acfb702295570e2cd837c Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:21:54 -0400 Subject: [PATCH 10/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 1340e21..199f2ae 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -239,7 +239,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { DisableKeystrokeHistory(); - Task.Delay(1000).ContinueWith(t=> OnKeystrokeHistorySettingChanged()) + Task.Delay(200).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); } } break; From cc090bd17210b6a55ddae158c2b4f81a3c8bb998 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:29:21 -0400 Subject: [PATCH 11/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 199f2ae..83141f8 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -239,7 +239,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { DisableKeystrokeHistory(); - Task.Delay(200).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); + Task.Delay(300).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); } } break; @@ -289,7 +289,13 @@ private void EnableKeystrokeHistory() if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) return; KeystrokeHistoryVisible = true; // Prevent Recursive call - KeystrokeHistoryWindow = new KeystrokeDisplay(myKeystrokeConverter, mySettings); + if (mySettings.EnableCursorFollow) + { + EnableMouseHook(); + KeystrokeHistoryWindow = new KeystrokeDisplay(myMouseHook, myKeystrokeConverter, mySettings); + }else{ + KeystrokeHistoryWindow = new KeystrokeDisplay(myKeystrokeConverter, mySettings); + } KeystrokeHistoryWindow.Show(); } @@ -298,6 +304,7 @@ private void DisableKeystrokeHistory() KeystrokeHistoryVisible = false; if (KeystrokeHistoryWindow == null) return; + DisableMouseHookIfNotNeeded(); KeystrokeHistoryWindow.Close(); KeystrokeHistoryWindow = null; } @@ -440,7 +447,7 @@ private void EnableMouseHook() private void DisableMouseHookIfNotNeeded() { - if (CursorIndicatorWindow == null && ButtonIndicatorWindow == null && AnnotateLineWindow == null) + if (CursorIndicatorWindow == null && ButtonIndicatorWindow == null && AnnotateLineWindow == null && (!mySettings.EnableCursorFollow || KeystrokeHistoryWindow == null)) DisableMouseHook(); } From 54bcfd26729b1c956c0c6756754f3d4975ec331f Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:42:51 -0400 Subject: [PATCH 12/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 83141f8..d1c9cc9 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -41,6 +41,7 @@ public static void Main() Settings1 settingsWindow; KeystrokeDisplay KeystrokeHistoryWindow = null; bool KeystrokeHistoryVisible = false; + bool attachedToMouse = false protected override void OnStartup(StartupEventArgs e) { @@ -234,13 +235,16 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - if (mySettings.EnableCursorFollow) + if (mySettings.EnableCursorFollow && !attachedToMouse) { if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { DisableKeystrokeHistory(); Task.Delay(300).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); } + attachedToMouse = true + }else{ + attachedToMouse = false } break; case "EnableAnnotateLine": From f7e8ca4d8f53470b07215ae74bc08cbd4c0e67e9 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:47:30 -0400 Subject: [PATCH 13/25] Update KeystrokeDisplay.xaml.cs --- KeyNStroke/KeystrokeDisplay.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KeyNStroke/KeystrokeDisplay.xaml.cs b/KeyNStroke/KeystrokeDisplay.xaml.cs index 3963258..a3146aa 100644 --- a/KeyNStroke/KeystrokeDisplay.xaml.cs +++ b/KeyNStroke/KeystrokeDisplay.xaml.cs @@ -103,8 +103,8 @@ void UpdatePosition(NativeMethodsMouse.POINT cursorPosition) NativeMethodsWindow.GetDpiForMonitor(monitor, NativeMethodsWindow.DpiType.MDT_EFFECTIVE_DPI, ref adpiX, ref adpiY); Log.e("CI", $"apix={adpiX} adpiy={adpiY} aw={ActualWidth} ah={ActualHeight} cx={cursorPosition.X} cy={cursorPosition.Y}"); NativeMethodsWindow.SetWindowPosition(windowHandle, - (int)((cursorPosition.X + 82) * (double)adpiX / 96.0), - (int)((cursorPosition.Y + 82) * (double)adpiY / 96.0)); + (int)((cursorPosition.X + settings.ButtonIndicatorPositionDistance) * (double)adpiX / 96.0), + (int)((cursorPosition.Y + settings.ButtonIndicatorPositionDistance) * (double)adpiY / 96.0)); } void SetFormStyles() From 8ecfed77784dab04582801b6d85d375f56799451 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 19:52:28 -0400 Subject: [PATCH 14/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index d1c9cc9..5f300ad 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -41,7 +41,7 @@ public static void Main() Settings1 settingsWindow; KeystrokeDisplay KeystrokeHistoryWindow = null; bool KeystrokeHistoryVisible = false; - bool attachedToMouse = false + bool attachedToMouse = false; protected override void OnStartup(StartupEventArgs e) { @@ -237,14 +237,14 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) case "EnableCursorFollow": if (mySettings.EnableCursorFollow && !attachedToMouse) { + attachedToMouse = true; if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { DisableKeystrokeHistory(); - Task.Delay(300).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); + Task.Delay(100).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); } - attachedToMouse = true }else{ - attachedToMouse = false + attachedToMouse = false; } break; case "EnableAnnotateLine": From 3ca0ed9581e0c1b10b86f1fcf19fcb49c8d83d1a Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:03:40 -0400 Subject: [PATCH 15/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 5f300ad..66aa4fb 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -237,13 +237,11 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) case "EnableCursorFollow": if (mySettings.EnableCursorFollow && !attachedToMouse) { + ReloadKeystrokeHistory(); attachedToMouse = true; - if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) - { - DisableKeystrokeHistory(); - Task.Delay(100).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); - } - }else{ + } else if (!mySettings.EnableCursorFollow && attachedToMouse) + { + ReloadKeystrokeHistory(); attachedToMouse = false; } break; @@ -288,6 +286,14 @@ private void OnKeystrokeHistorySettingChanged() } } + private void ReloadKeystrokeHistory(){ + if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) + { + DisableKeystrokeHistory(); + Task.Delay(300).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); + } + } + private void EnableKeystrokeHistory() { if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) From 9049ff60ca95f90bad29ac4e6eda08ced45cd3ac Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:16:34 -0400 Subject: [PATCH 16/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 66aa4fb..6e86f26 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -274,6 +274,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) #region Keystroke History + private void shouldReopen = false; private void OnKeystrokeHistorySettingChanged() { if (mySettings.EnableKeystrokeHistory && !mySettings.Standby) @@ -288,9 +289,9 @@ private void OnKeystrokeHistorySettingChanged() private void ReloadKeystrokeHistory(){ if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) - { + { + shouldReopen = true DisableKeystrokeHistory(); - Task.Delay(300).ContinueWith(t=> OnKeystrokeHistorySettingChanged()); } } @@ -307,6 +308,15 @@ private void EnableKeystrokeHistory() KeystrokeHistoryWindow = new KeystrokeDisplay(myKeystrokeConverter, mySettings); } KeystrokeHistoryWindow.Show(); + KeystrokeHistoryWindow.Closed += new EventHandler(KeystrokeClosed); + } + + private void KeystrokeClosed(object sender, EventArgs e) + { + if (shouldReopen && mySettings.EnableKeystrokeHistory) + { + EnableKeystrokeHistory() + } } private void DisableKeystrokeHistory() From 8934adca24c8b680b657f0909d52c7abe64dd355 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:18:33 -0400 Subject: [PATCH 17/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 6e86f26..2607ef6 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -274,7 +274,8 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) #region Keystroke History - private void shouldReopen = false; + bool shouldReopen = false; + private void OnKeystrokeHistorySettingChanged() { if (mySettings.EnableKeystrokeHistory && !mySettings.Standby) @@ -290,7 +291,7 @@ private void OnKeystrokeHistorySettingChanged() private void ReloadKeystrokeHistory(){ if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) { - shouldReopen = true + shouldReopen = true; DisableKeystrokeHistory(); } } @@ -315,7 +316,8 @@ private void KeystrokeClosed(object sender, EventArgs e) { if (shouldReopen && mySettings.EnableKeystrokeHistory) { - EnableKeystrokeHistory() + EnableKeystrokeHistory(); + shouldReopen = false; } } From a5850cacf2afddf0c56542765612a204f9e7f605 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:34:22 -0400 Subject: [PATCH 18/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 2607ef6..475dba1 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -41,7 +41,7 @@ public static void Main() Settings1 settingsWindow; KeystrokeDisplay KeystrokeHistoryWindow = null; bool KeystrokeHistoryVisible = false; - bool attachedToMouse = false; + bool attached = false; protected override void OnStartup(StartupEventArgs e) { @@ -235,14 +235,12 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - if (mySettings.EnableCursorFollow && !attachedToMouse) + if (!attached) { - ReloadKeystrokeHistory(); - attachedToMouse = true; - } else if (!mySettings.EnableCursorFollow && attachedToMouse) - { - ReloadKeystrokeHistory(); - attachedToMouse = false; + attached = true; + } else { + Application.Restart(); //We do a restart to avoid some bugs + Environment.Exit(0); } break; case "EnableAnnotateLine": @@ -274,8 +272,6 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) #region Keystroke History - bool shouldReopen = false; - private void OnKeystrokeHistorySettingChanged() { if (mySettings.EnableKeystrokeHistory && !mySettings.Standby) @@ -288,14 +284,6 @@ private void OnKeystrokeHistorySettingChanged() } } - private void ReloadKeystrokeHistory(){ - if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) - { - shouldReopen = true; - DisableKeystrokeHistory(); - } - } - private void EnableKeystrokeHistory() { if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null) @@ -309,16 +297,6 @@ private void EnableKeystrokeHistory() KeystrokeHistoryWindow = new KeystrokeDisplay(myKeystrokeConverter, mySettings); } KeystrokeHistoryWindow.Show(); - KeystrokeHistoryWindow.Closed += new EventHandler(KeystrokeClosed); - } - - private void KeystrokeClosed(object sender, EventArgs e) - { - if (shouldReopen && mySettings.EnableKeystrokeHistory) - { - EnableKeystrokeHistory(); - shouldReopen = false; - } } private void DisableKeystrokeHistory() From 11fd4f3310072bbe9e32e4dbf65321b40177c07f Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:40:55 -0400 Subject: [PATCH 19/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 475dba1..4d0c918 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -239,7 +239,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) { attached = true; } else { - Application.Restart(); //We do a restart to avoid some bugs + System.Windows.Forms.Application.Restart(); //We do a restart to avoid some bugs Environment.Exit(0); } break; From be2772f8b2a2f10b841dfa70b01df6b4087a0f58 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:54:13 -0400 Subject: [PATCH 20/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 4d0c918..2174cfc 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -41,7 +41,7 @@ public static void Main() Settings1 settingsWindow; KeystrokeDisplay KeystrokeHistoryWindow = null; bool KeystrokeHistoryVisible = false; - bool attached = false; + bool attached = null; protected override void OnStartup(StartupEventArgs e) { @@ -235,11 +235,12 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) OnKeystrokeHistorySettingChanged(); break; case "EnableCursorFollow": - if (!attached) + if (attached==null) { - attached = true; - } else { - System.Windows.Forms.Application.Restart(); //We do a restart to avoid some bugs + attached = mySettings.EnableCursorFollow + }else if (attached != mySettings.EnableCursorFollow) + { + Application.Restart(); //We do a restart to avoid some bugs Environment.Exit(0); } break; From 3f39d186f839c90166c55f3d948432758d616525 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 20:55:10 -0400 Subject: [PATCH 21/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 2174cfc..399d57f 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -237,7 +237,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) case "EnableCursorFollow": if (attached==null) { - attached = mySettings.EnableCursorFollow + attached = mySettings.EnableCursorFollow; }else if (attached != mySettings.EnableCursorFollow) { Application.Restart(); //We do a restart to avoid some bugs From f1c6612391f5f7e2f32d844b1fc30dc9b93dcc74 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 21:03:11 -0400 Subject: [PATCH 22/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 399d57f..5e099a1 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -41,7 +41,7 @@ public static void Main() Settings1 settingsWindow; KeystrokeDisplay KeystrokeHistoryWindow = null; bool KeystrokeHistoryVisible = false; - bool attached = null; + bool? attached = null; protected override void OnStartup(StartupEventArgs e) { @@ -240,7 +240,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) attached = mySettings.EnableCursorFollow; }else if (attached != mySettings.EnableCursorFollow) { - Application.Restart(); //We do a restart to avoid some bugs + System.Windows.Forms.Application.Restart(); //We do a restart to avoid some bugs Environment.Exit(0); } break; From 6e77b873ff22065e4615e60e4c474467292170c9 Mon Sep 17 00:00:00 2001 From: elMuso <42069617+elMuso@users.noreply.github.com> Date: Sat, 26 Feb 2022 21:12:52 -0400 Subject: [PATCH 23/25] Update App.xaml.cs --- KeyNStroke/App.xaml.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/KeyNStroke/App.xaml.cs b/KeyNStroke/App.xaml.cs index 5e099a1..7738efc 100644 --- a/KeyNStroke/App.xaml.cs +++ b/KeyNStroke/App.xaml.cs @@ -240,6 +240,7 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e) attached = mySettings.EnableCursorFollow; }else if (attached != mySettings.EnableCursorFollow) { + mySettings.SaveAll(); System.Windows.Forms.Application.Restart(); //We do a restart to avoid some bugs Environment.Exit(0); } From d5522a96c209e1410610c33c5cc93bf8443f7ab3 Mon Sep 17 00:00:00 2001 From: ayRatul Date: Sun, 27 Feb 2022 18:32:21 -0400 Subject: [PATCH 24/25] Added custom cursor follow distance, to avoid problems when windows upscales the screen elements --- KeyNStroke/KeystrokeDisplay.xaml.cs | 4 ++-- KeyNStroke/Settings1.xaml | 5 +++++ KeyNStroke/SettingsStore.cs | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/KeyNStroke/KeystrokeDisplay.xaml.cs b/KeyNStroke/KeystrokeDisplay.xaml.cs index a3146aa..ac0c2f5 100644 --- a/KeyNStroke/KeystrokeDisplay.xaml.cs +++ b/KeyNStroke/KeystrokeDisplay.xaml.cs @@ -103,8 +103,8 @@ void UpdatePosition(NativeMethodsMouse.POINT cursorPosition) NativeMethodsWindow.GetDpiForMonitor(monitor, NativeMethodsWindow.DpiType.MDT_EFFECTIVE_DPI, ref adpiX, ref adpiY); Log.e("CI", $"apix={adpiX} adpiy={adpiY} aw={ActualWidth} ah={ActualHeight} cx={cursorPosition.X} cy={cursorPosition.Y}"); NativeMethodsWindow.SetWindowPosition(windowHandle, - (int)((cursorPosition.X + settings.ButtonIndicatorPositionDistance) * (double)adpiX / 96.0), - (int)((cursorPosition.Y + settings.ButtonIndicatorPositionDistance) * (double)adpiY / 96.0)); + (int)((cursorPosition.X + settings.CursorFollowDistance) * (double)adpiX / 96.0), + (int)((cursorPosition.Y + settings.CursorFollowDistance) * (double)adpiY / 96.0)); } void SetFormStyles() diff --git a/KeyNStroke/Settings1.xaml b/KeyNStroke/Settings1.xaml index ec426f9..4ace8d3 100644 --- a/KeyNStroke/Settings1.xaml +++ b/KeyNStroke/Settings1.xaml @@ -100,6 +100,11 @@ Minimum="10.0" Maximum="100.0" Value="{Binding LineDistance, Mode=TwoWay}" /> + enableWindowFade = null; [DataMember] public Nullable enableCursorIndicator = null; [DataMember] public Nullable enableCursorFollow = null; + [DataMember] public Nullable cursorFollowDistance = null; [DataMember] public Nullable cursorIndicatorOpacity = null; [DataMember] public Nullable cursorIndicatorSize = null; [DataMember] public SerializableColor2 cursorIndicatorColor = null; @@ -424,6 +425,13 @@ public bool EnableCursorFollow set { i.enableCursorFollow = value; OnSettingChanged("EnableCursorFollow"); } } + public double CursorFollowDistanceDefault = 56; + public double CursorFollowDistance + { + get { return Or(i.cursorFollowDistance, CursorFollowDistanceDefault); } + set { i.cursorFollowDistance = value; OnSettingChanged("CursorFollowDistance"); } + } + public double CursorIndicatorOpacityDefault = 0.3; public double CursorIndicatorOpacity { @@ -703,6 +711,7 @@ public void CallPropertyChangedForAllProperties() PropertyChanged(this, new PropertyChangedEventArgs("EnableWindowFade")); PropertyChanged(this, new PropertyChangedEventArgs("EnableCursorIndicator")); PropertyChanged(this, new PropertyChangedEventArgs("EnableCursorFollow")); + PropertyChanged(this, new PropertyChangedEventArgs("CursorFollowDistance")); PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorOpacity")); PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorSize")); PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorColor")); @@ -837,6 +846,7 @@ public override string ToString() EnableWindowFade: {EnableWindowFade} EnableCursorIndicator: {EnableCursorIndicator} EnableCursorFollow: {EnableCursorFollow} +CursorFollowDistance: {CursorFollowDistance} CursorIndicatorOpacity: {CursorIndicatorOpacity} CursorIndicatorSize: {CursorIndicatorSize} CursorIndicatorColor: {CursorIndicatorColor} From 7bedb5d509646338a7487653d99296abfe3a0f63 Mon Sep 17 00:00:00 2001 From: ayRatul Date: Sun, 27 Feb 2022 18:47:05 -0400 Subject: [PATCH 25/25] removed unnecesary calculations --- KeyNStroke/KeystrokeDisplay.xaml.cs | 8 ++------ KeyNStroke/Settings1.xaml | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/KeyNStroke/KeystrokeDisplay.xaml.cs b/KeyNStroke/KeystrokeDisplay.xaml.cs index ac0c2f5..0ac9da5 100644 --- a/KeyNStroke/KeystrokeDisplay.xaml.cs +++ b/KeyNStroke/KeystrokeDisplay.xaml.cs @@ -98,13 +98,9 @@ void m_MouseEvent(MouseRawEventArgs raw_e) void UpdatePosition(NativeMethodsMouse.POINT cursorPosition) { - IntPtr monitor = NativeMethodsWindow.MonitorFromPoint(cursorPosition, NativeMethodsWindow.MonitorOptions.MONITOR_DEFAULTTONEAREST); - uint adpiX = 0, adpiY = 0; - NativeMethodsWindow.GetDpiForMonitor(monitor, NativeMethodsWindow.DpiType.MDT_EFFECTIVE_DPI, ref adpiX, ref adpiY); - Log.e("CI", $"apix={adpiX} adpiy={adpiY} aw={ActualWidth} ah={ActualHeight} cx={cursorPosition.X} cy={cursorPosition.Y}"); NativeMethodsWindow.SetWindowPosition(windowHandle, - (int)((cursorPosition.X + settings.CursorFollowDistance) * (double)adpiX / 96.0), - (int)((cursorPosition.Y + settings.CursorFollowDistance) * (double)adpiY / 96.0)); + (int)(cursorPosition.X + settings.CursorFollowDistance), + (int)(cursorPosition.Y + settings.CursorFollowDistance)); } void SetFormStyles() diff --git a/KeyNStroke/Settings1.xaml b/KeyNStroke/Settings1.xaml index 4ace8d3..703b5f8 100644 --- a/KeyNStroke/Settings1.xaml +++ b/KeyNStroke/Settings1.xaml @@ -101,7 +101,7 @@ Maximum="100.0" Value="{Binding LineDistance, Mode=TwoWay}" />