Skip to content

Commit 5e3b4c3

Browse files
committed
The user can now choose if they want to border or background to be highlighted on key press
The user can change these settings in the config.txt. I also added a helper function for grabbing specific lines of the config.txt. The reason why is because the other way I did it was tedious and hard for me to wrap my head around, but this is pretty straightforward.
1 parent 53e1ec2 commit 5e3b4c3

File tree

2 files changed

+70
-33
lines changed

2 files changed

+70
-33
lines changed

EvadeKeystrokes.xaml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@
1717
Closing="WindowClose"
1818
Topmost="True">
1919
<Grid x:Name="WindowGrid">
20-
<Button x:Name="WKeystroke" Content="W" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="120,65,0,0" BorderBrush="{x:Null}"/>
21-
<Button x:Name="AKeystroke" Content="A" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" Margin="80,105,0,0" FontSize="20" BorderBrush="{x:Null}"/>
22-
<Button x:Name="SKeystroke" Content="S" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" Margin="120,105,0,0" FontSize="20" BorderBrush="{x:Null}"/>
23-
<Button x:Name="DKeystroke" Content="D" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" Margin="160,105,0,0" FontSize="20" BorderBrush="{x:Null}"/>
24-
<Button x:Name="OneKeystroke" Content="1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="210,105,0,0" BorderBrush="{x:Null}"/>
25-
<Button x:Name="TwoKeystroke" Content="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="255,105,0,0" BorderBrush="{x:Null}"/>
26-
<Button x:Name="RKeystroke" Content="R" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="210,150,0,0" BorderBrush="{x:Null}"/>
27-
<Button x:Name="TKeystroke" Content="T" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="255,150,0,0" BorderBrush="{x:Null}"/>
28-
<Button x:Name="SpacebarKeystroke" Content="Space" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="40" FontSize="20" Margin="80,150,0,0" BorderBrush="{x:Null}"/>
20+
<Button x:Name="WKeystroke" Content="W" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="120,65,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
21+
<Button x:Name="AKeystroke" Content="A" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" Margin="80,105,0,0" FontSize="20" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
22+
<Button x:Name="SKeystroke" Content="S" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" Margin="120,105,0,0" FontSize="20" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
23+
<Button x:Name="DKeystroke" Content="D" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" Margin="160,105,0,0" FontSize="20" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
24+
<Button x:Name="OneKeystroke" Content="1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="210,105,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
25+
<Button x:Name="TwoKeystroke" Content="2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="255,105,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
26+
<Button x:Name="RKeystroke" Content="R" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="210,150,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
27+
<Button x:Name="TKeystroke" Content="T" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="255,150,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
28+
<Button x:Name="SpacebarKeystroke" Content="Space" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="40" FontSize="20" Margin="80,150,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
2929
<Canvas x:Name="InvisibleCanvas" ZIndex="-1" MouseLeftButtonDown="WindowMove" Background="#01000000"/>
30-
<Button x:Name="CtrlorCKeystroke" Content="Ctrl/C" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="40" FontSize="20" Margin="80,195,0,0" BorderBrush="{x:Null}"/>
31-
<Button x:Name="EKeystroke" Content="E" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="210,195,0,0" BorderBrush="{x:Null}"/>
32-
<Button x:Name="QKeystroke" Content="Q" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="255,195,0,0" BorderBrush="{x:Null}"/>
30+
<Button x:Name="CtrlorCKeystroke" Content="Ctrl/C" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Height="40" FontSize="20" Margin="80,195,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
31+
<Button x:Name="EKeystroke" Content="E" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="210,195,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
32+
<Button x:Name="QKeystroke" Content="Q" HorizontalAlignment="Left" VerticalAlignment="Top" Width="40" Height="40" FontSize="20" Margin="255,195,0,0" BorderBrush="{x:Null}" BorderThickness="2,2,2,2"/>
3333
</Grid>
3434
</Window>

EvadeKeystrokes.xaml.cs

Lines changed: 58 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ namespace EvadeKeystrokes
2020
public partial class MainWindow : Window
2121
{
2222
private IKeyboardMouseEvents m_GlobalHook;
23-
private static Brush BackgroundValue;
24-
private static Brush PressedBackgroundValue;
23+
private static Brush BackgroundBorderValue;
24+
private static Brush PressedValue;
2525
private static Brush ForegroundValue;
26-
private static string buttonBackground;
27-
private static string pressedButtonBackground;
26+
private static string buttonBorderValue;
27+
private static string pressedButtonValue;
2828
private static string buttonForeground;
2929

30-
private readonly string DefaultPressedBackgroundValue = "#FFBEE6FD";
31-
private readonly string DefaultBackgroundValue = "#FFDDDDDD";
30+
private readonly string DefaultPressedValue = "#FFBEE6FD";
31+
private readonly string DefaultBackgroundBorderValue = "#FFDDDDDD";
3232
private readonly string DefaultForegroundValue = "#FF000000";
3333

34+
private bool useBorder;
35+
3436
public MainWindow()
3537
{
3638
InitializeComponent();
@@ -46,16 +48,20 @@ private void CreateConfig()
4648

4749
string text =
4850
"# 1st line is for button background\n" +
49-
"# 2nd line is for button background when pressed\n" +
50-
"# 3rd line is for button foreground\n\n" +
51-
$"{DefaultBackgroundValue}\n" +
52-
$"{DefaultPressedBackgroundValue}\n" +
53-
$"{DefaultForegroundValue}";
51+
"# 2nd line is for button background/border when pressed\n" +
52+
"# 3rd line is for button foreground\n" +
53+
"# 4rd line is to tell Evade Keystrokes if you want to highlight the background or border when a key is pressed\n" +
54+
"# For example, useborder:false would tell Evade Keystrokes to highlight the background\n" +
55+
"# useborder:true would tell Evade Keystrokes to highlight the border\n\n" +
56+
$"{DefaultBackgroundBorderValue}\n" +
57+
$"{DefaultPressedValue}\n" +
58+
$"{DefaultForegroundValue}\n" +
59+
"useborder:false";
5460

5561
File.WriteAllText("config.txt", text);
5662

57-
BackgroundValue = new BrushConverter().ConvertFromString(DefaultBackgroundValue) as Brush;
58-
PressedBackgroundValue = new BrushConverter().ConvertFromString(DefaultPressedBackgroundValue) as Brush;
63+
BackgroundBorderValue = new BrushConverter().ConvertFromString(DefaultBackgroundBorderValue) as Brush;
64+
PressedValue = new BrushConverter().ConvertFromString(DefaultPressedValue) as Brush;
5965
ForegroundValue = new BrushConverter().ConvertFromString(DefaultForegroundValue) as Brush;
6066
}
6167
else
@@ -66,21 +72,32 @@ private void CreateConfig()
6672

6773
private void LoadConfig()
6874
{
69-
buttonBackground = File.ReadLines("config.txt").Skip(4).Take(1).First();
70-
pressedButtonBackground = File.ReadLines("config.txt").Skip(5).Take(1).First();
71-
buttonForeground = File.ReadLines("config.txt").Skip(6).Take(1).First();
75+
buttonBorderValue = GetLine(8);
76+
pressedButtonValue = GetLine(9);
77+
buttonForeground = GetLine(10);
78+
useBorder = GetLine(11) == "useborder:true";
7279

73-
BackgroundValue = new BrushConverter().ConvertFromString(buttonBackground) as Brush;
74-
PressedBackgroundValue = new BrushConverter().ConvertFromString(pressedButtonBackground) as Brush;
80+
BackgroundBorderValue = new BrushConverter().ConvertFromString(buttonBorderValue) as Brush;
81+
PressedValue = new BrushConverter().ConvertFromString(pressedButtonValue) as Brush;
7582
ForegroundValue = new BrushConverter().ConvertFromString(buttonForeground) as Brush;
7683

7784
foreach (Button button in FindVisualChildren<Button>(WindowGrid))
7885
{
79-
button.Background = BackgroundValue;
86+
button.Background = BackgroundBorderValue;
8087
button.Foreground = ForegroundValue;
8188
}
8289
}
8390

91+
string GetLine(int line)
92+
{
93+
using (var sr = new StreamReader("config.txt"))
94+
{
95+
for (int i = 1; i < line; i++)
96+
sr.ReadLine();
97+
return sr.ReadLine();
98+
}
99+
}
100+
84101
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
85102
{
86103
if (depObj == null) yield return (T)Enumerable.Empty<T>();
@@ -95,9 +112,29 @@ public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) wher
95112

96113
private void WindowClose(object sender, System.ComponentModel.CancelEventArgs e) => Unsubscribe();
97114

98-
private void ActivateButton(Button buttonName) => buttonName.Background = PressedBackgroundValue;
115+
private void ActivateButton(Button buttonName)
116+
{
117+
if (useBorder)
118+
{
119+
buttonName.BorderBrush = PressedValue;
120+
}
121+
else
122+
{
123+
buttonName.Background = PressedValue;
124+
}
125+
}
99126

100-
private void DeactivateButton(Button buttonName) => buttonName.Background = BackgroundValue;
127+
private void DeactivateButton(Button buttonName)
128+
{
129+
if (useBorder)
130+
{
131+
buttonName.BorderBrush = BackgroundBorderValue;
132+
}
133+
else
134+
{
135+
buttonName.Background = BackgroundBorderValue;
136+
}
137+
}
101138

102139
public void Subscribe()
103140
{

0 commit comments

Comments
 (0)