Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion KeyNStroke/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ private void OnSettingChanged(object sender, PropertyChangedEventArgs e)
case "EnableKeystrokeHistory":
OnKeystrokeHistorySettingChanged();
break;
case "PauseCursorDifferentScreen":
OnPauseCursorDifferentScreenChanged();
break;
case "EnableAnnotateLine":
OnAnnotateLineSettingChanged();
break;
Expand Down Expand Up @@ -280,7 +283,7 @@ private void EnableKeystrokeHistory()
if (KeystrokeHistoryVisible || KeystrokeHistoryWindow != null)
return;
KeystrokeHistoryVisible = true; // Prevent Recursive call
KeystrokeHistoryWindow = new KeystrokeDisplay(myKeystrokeConverter, mySettings);
KeystrokeHistoryWindow = new KeystrokeDisplay(myKeystrokeConverter, myMouseHook, mySettings);
KeystrokeHistoryWindow.Show();
}

Expand All @@ -293,6 +296,14 @@ private void DisableKeystrokeHistory()
KeystrokeHistoryWindow = null;
}

private void OnPauseCursorDifferentScreenChanged()
{
if (KeystrokeHistoryWindow != null)
{
KeystrokeHistoryWindow.UpdateDisplayScreenName();
}
}

#endregion

#region Button Indicator
Expand Down
33 changes: 32 additions & 1 deletion KeyNStroke/KeystrokeDisplay.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ public partial class KeystrokeDisplay : Window
{
readonly SettingsStore settings;
readonly IKeystrokeEventProvider k;
readonly IMouseRawEventProvider m;
IntPtr windowHandle;
Brush OrigInnerPanelBackgroundColor;

public KeystrokeDisplay(IKeystrokeEventProvider k, SettingsStore s)
public KeystrokeDisplay(IKeystrokeEventProvider k, IMouseRawEventProvider m, SettingsStore s)
{
InitializeComponent();
InitializeAnimations();

this.k = k;
this.m = m;

this.settings = s;
this.settings.EnableSettingsMode = false;
Expand All @@ -58,17 +60,27 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
windowHandle = new WindowInteropHelper(this).Handle;

this.k.KeystrokeEvent += KeystrokeEvent;
this.m.MouseEvent += MouseEvent;

OrigInnerPanelBackgroundColor = innerPanel.Background;
ActivateDisplayOnlyMode(true);
DeactivatePasswordProtectionMode(true);
UpdateDisplayScreenName();

if (settings.EnableWindowFade)
{
FadeOut();
}
}

private string _deviceName;

public void UpdateDisplayScreenName()
{
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromPoint(new System.Drawing.Point(Convert.ToInt32(this.Left), Convert.ToInt32(this.Top)));
_deviceName = screen.DeviceName;
}

#region periodically make TopMost
readonly DispatcherTimer makeTopMostTimer = new DispatcherTimer();
void InitPeriodicTopmostTimer()
Expand Down Expand Up @@ -118,6 +130,12 @@ void KeystrokeEvent(KeystrokeEventArgs e)
return;
}

if (settings.PauseCursorDifferentScreen
&& _cursorDeviceName != _deviceName)
{
return;
}

if (e.ShouldBeDisplayed)
{
if (settings.EnableWindowFade && !SettingsModeActivated)
Expand Down Expand Up @@ -184,6 +202,18 @@ void KeystrokeEvent(KeystrokeEventArgs e)
}


#endregion

#region Cursor event handler

private string _cursorDeviceName;

private void MouseEvent(MouseRawEventArgs e)
{
System.Windows.Forms.Screen screen = System.Windows.Forms.Screen.FromPoint(e.Position);
_cursorDeviceName = screen.DeviceName;
}

#endregion

#region Opacity Animation
Expand Down Expand Up @@ -602,6 +632,7 @@ private void Window_Closing(object sender, CancelEventArgs e)
private void ButtonLeaveSettingsMode_Click(object sender, RoutedEventArgs e)
{
settings.EnableSettingsMode = false;
UpdateDisplayScreenName();
}

#endregion
Expand Down
5 changes: 5 additions & 0 deletions KeyNStroke/Settings1.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@
IsChecked="{Binding EnableWindowFade}">Hide window when empty</CheckBox>
<CheckBox x:Name="cb_periodictopmost"
IsChecked="{Binding PeriodicTopmost}">Put on top periodically</CheckBox>
<CheckBox x:Name="cb_pausecursordifferentscreen_enable"
IsChecked="{Binding PauseCursorDifferentScreen}"
ToolTip="Stop tracking keystroke when cursor and keystroke history window are on different screens in a multiple monitors setup">
<TextBlock TextWrapping="Wrap"><Run Text="Pause when cursor and keystroke window are on different screens" /></TextBlock>
</CheckBox>
</StackPanel>
</StackPanel>
<StackPanel Margin="5"
Expand Down
2 changes: 2 additions & 0 deletions KeyNStroke/Settings1.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ private void Bn_reset_position_Click(object sender, RoutedEventArgs e)
settings.PanelSize = settings.PanelSizeDefault;
settings.WindowLocation = settings.WindowLocationDefault;
settings.WindowSize = settings.WindowSizeDefault;

settings.CallPropertyChangedForAllProperties();
}

private void bn_reset_all_Click(object sender, RoutedEventArgs e)
Expand Down
10 changes: 10 additions & 0 deletions KeyNStroke/SettingsStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ class Settings
[DataMember] public Nullable<bool> enableHistoryTimeout = null;
[DataMember] public Nullable<bool> enableWindowFade = null;
[DataMember] public Nullable<bool> enableCursorIndicator = null;
[DataMember] public Nullable<bool> pauseCursorDifferentScreen = null;
[DataMember] public Nullable<double> cursorIndicatorOpacity = null;
[DataMember] public Nullable<double> cursorIndicatorSize = null;
[DataMember] public SerializableColor2 cursorIndicatorColor = null;
Expand Down Expand Up @@ -416,6 +417,13 @@ public bool EnableCursorIndicator
set { i.enableCursorIndicator = value; OnSettingChanged("EnableCursorIndicator"); }
}

public bool PauseCursorDifferentScreenDefault = false;
public bool PauseCursorDifferentScreen
{
get { return Or(i.pauseCursorDifferentScreen, PauseCursorDifferentScreenDefault); }
set { i.pauseCursorDifferentScreen = value; OnSettingChanged("PauseCursorDifferentScreen"); }
}

public double CursorIndicatorOpacityDefault = 0.3;
public double CursorIndicatorOpacity
{
Expand Down Expand Up @@ -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("PauseCursorDifferentScreen"));
PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorOpacity"));
PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorSize"));
PropertyChanged(this, new PropertyChangedEventArgs("CursorIndicatorColor"));
Expand Down Expand Up @@ -827,6 +836,7 @@ public override string ToString()
EnableHistoryTimeout: {EnableHistoryTimeout}
EnableWindowFade: {EnableWindowFade}
EnableCursorIndicator: {EnableCursorIndicator}
PauseCursorDifferentScreen: {PauseCursorDifferentScreen}
CursorIndicatorOpacity: {CursorIndicatorOpacity}
CursorIndicatorSize: {CursorIndicatorSize}
CursorIndicatorColor: {CursorIndicatorColor}
Expand Down