Skip to content

Commit

Permalink
Added some epic comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Plextora committed Nov 19, 2022
1 parent 4ab5b66 commit b921b70
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions EvadeKeystrokes.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
using Button = System.Windows.Controls.Button;
using KeyEventArgs = System.Windows.Forms.KeyEventArgs;

#region Todo list
/*
* Clean up OnKeyDown and OnKeyUp functions
* (Maybe) fix redundant variables
*/
#endregion

namespace EvadeKeystrokes
{
/// <summary>
Expand Down Expand Up @@ -45,6 +52,7 @@ private void CreateConfig()
{
if (!File.Exists("config.txt"))
{
// actually creates the config.txt
File.Create("config.txt").Close();

string text =
Expand All @@ -61,6 +69,7 @@ private void CreateConfig()

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

// Loads default config
BackgroundBorderValue = new BrushConverter().ConvertFromString(DefaultBackgroundBorderValue) as Brush;
PressedValue = new BrushConverter().ConvertFromString(DefaultPressedValue) as Brush;
ForegroundValue = new BrushConverter().ConvertFromString(DefaultForegroundValue) as Brush;
Expand All @@ -73,15 +82,23 @@ private void CreateConfig()

private void LoadConfig()
{
// assign variables to lines from config.txt
buttonBorderValue = GetLine(8);
pressedButtonValue = GetLine(9);
buttonForeground = GetLine(10);
useBorder = GetLine(11) == "useborder:true";

/*
* I only use buttonBorderValue, pressedButtonValue, and buttonForeground once or twice.
* This also happens in another functions as well
* Kinda redundant?
* idk, probably wont fix this but it goes in the todo list anyways
*/
BackgroundBorderValue = new BrushConverter().ConvertFromString(buttonBorderValue) as Brush;
PressedValue = new BrushConverter().ConvertFromString(pressedButtonValue) as Brush;
ForegroundValue = new BrushConverter().ConvertFromString(buttonForeground) as Brush;

// Assigns all of the buttons backgrounds and foregrounds to BackgroundBorderValue and ForegroundValue
foreach (Button button in FindVisualChildren<Button>(WindowGrid))
{
button.Background = BackgroundBorderValue;
Expand All @@ -99,6 +116,10 @@ string GetLine(int line)
}
}

/*
* I have no idea why or how it works but it works but thank you StackOverflow gods
* https://stackoverflow.com/a/978352/20083929
*/
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj == null) yield return (T)Enumerable.Empty<T>();
Expand All @@ -113,6 +134,8 @@ public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) wher

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


// Make the button look like it's pressed using the user's config values
private void ActivateButton(Button buttonName)
{
if (useBorder)
Expand All @@ -125,6 +148,7 @@ private void ActivateButton(Button buttonName)
}
}

// Make the button look normal using the user's config values
private void DeactivateButton(Button buttonName)
{
if (useBorder)
Expand All @@ -145,6 +169,8 @@ public void Subscribe()
m_GlobalHook.KeyUp += OnKeyUp;
}

// SPAGHETTI CODE INCOMING!!!

private void OnKeyDown(object sender, KeyEventArgs e)
{
switch (e.KeyCode)
Expand Down

0 comments on commit b921b70

Please sign in to comment.