using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;
using System.IO;
namespace LeagueDelete
{
internal static class Program
{
// Example mapping from certain keys to "process patterns"
// (like your original InactiveList).
// Instead of "CTRL+F1," we'll capture F1 at a low level
// and check if CTRL is down inside the hook's KeyDown event.
private static readonly Dictionary<Keys, List<string>> KeyToProcessList
= new Dictionary<Keys, List<string>>
{
{ Keys.F1, new List<string> {"League", "Riot"} },
{ Keys.F2, new List<string> {"Teams"} },
{ Keys.F3, new List<string> {"Discord"} },
{ Keys.F4, new List<string> {"Slack"} },
{ Keys.F5, new List<string> {"Steam"} },
{ Keys.F6, new List<string> {"Battle", "Blizzard", "Diablo", "Overwatch"} },
{ Keys.F7, new List<string> {"Chrome"} },
};
// Global hook instance
private static GlobalKeyboardHook gkh;
// Tray icon
private static NotifyIcon notifyIcon;
[STAThread]
static void Main()
{
// Initialize Windows Forms
ApplicationConfiguration.Initialize();
// (Optional) Allocate a console to see debug logs/errors:
// AllocConsole();
// Set up the notify icon with a context menu
var iconPath = Path.Combine(AppContext.BaseDirectory, "spat2.ico");
notifyIcon = new NotifyIcon
{
Icon = new Icon(iconPath),
Visible = true,
ContextMenuStrip = new ContextMenuStrip
{
Items =
{
new ToolStripMenuItem("Exit", null, (s, e) => Application.Exit()),
new ToolStripMenuItem("CTRL + F1 => Kill League/Riot"),
new ToolStripMenuItem("CTRL + F2 => Kill Teams"),
new ToolStripMenuItem("CTRL + F3 => Kill Discord"),
new ToolStripMenuItem("CTRL + F4 => Kill Slack"),
new ToolStripMenuItem("CTRL + F5 => Kill Steam"),
new ToolStripMenuItem("CTRL + F6 => Kill Battle/Blizzard/etc."),
new ToolStripMenuItem("CTRL + F7 => Kill Chrome")
}
}
};
// Create a global keyboard hook
gkh = new GlobalKeyboardHook();
// Hook the function keys we want to watch
gkh.HookedKeys.Add(Keys.F1);
gkh.HookedKeys.Add(Keys.F2);
gkh.HookedKeys.Add(Keys.F3);
gkh.HookedKeys.Add(Keys.F4);
gkh.HookedKeys.Add(Keys.F5);
gkh.HookedKeys.Add(Keys.F6);
gkh.HookedKeys.Add(Keys.F7);
// Event handlers for KeyDown/KeyUp
gkh.KeyDown += Gkh_KeyDown;
gkh.KeyUp += Gkh_KeyUp;
// Run the message loop
Application.Run();
}
private static void Gkh_KeyDown(object sender, KeyEventArgs e)
{
// Check if CTRL is down
bool ctrlIsDown = (Control.ModifierKeys & Keys.Control) == Keys.Control;
// If the pressed key is in our list AND CTRL is pressed
if (ctrlIsDown && KeyToProcessList.ContainsKey(e.KeyCode))
{
// Mark handled so the key doesn't pass to the game
e.Handled = true;
List<string> patterns = KeyToProcessList[e.KeyCode];
Debug.WriteLine($"[KeyDown] CTRL+{e.KeyCode} => kill patterns: {string.Join(", ", patterns)}");
// Start a 10-second kill task
Task.Run(() => KillProcessesRepeatedly(patterns));
}
}
private static void Gkh_KeyUp(object sender, KeyEventArgs e)
{
// For this scenario, we may not need KeyUp logic,
// but you can handle it if you like
}
private static void KillProcessesRepeatedly(List<string> processPatterns)
{
var start = DateTime.UtcNow;
while ((DateTime.UtcNow - start).TotalSeconds < 10)
{
var processes = Process.GetProcesses();
foreach (var p in processes)
{
// Don't kill ourself
if (p.Id == Process.GetCurrentProcess().Id)
continue;
// Compare each pattern
foreach (var pattern in processPatterns)
{
if (p.ProcessName.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) >= 0)
{
try
{
p.Kill();
}
catch
{
// ignore any exceptions
}
break; // done with this process
}
}
}
Thread.Sleep(100);
}
}
}
}