Advertisement
Guest User

LeagueKiller

a guest
Jan 30th, 2025
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using System.Windows.Forms;
  8. using System.Drawing;
  9. using System.IO;
  10.  
  11. namespace LeagueDelete
  12. {
  13.     internal static class Program
  14.     {
  15.         // Example mapping from certain keys to "process patterns"
  16.         // (like your original InactiveList).
  17.         // Instead of "CTRL+F1," we'll capture F1 at a low level
  18.         // and check if CTRL is down inside the hook's KeyDown event.
  19.         private static readonly Dictionary<Keys, List<string>> KeyToProcessList
  20.             = new Dictionary<Keys, List<string>>
  21.         {
  22.             { Keys.F1, new List<string> {"League", "Riot"} },
  23.             { Keys.F2, new List<string> {"Teams"} },
  24.             { Keys.F3, new List<string> {"Discord"} },
  25.             { Keys.F4, new List<string> {"Slack"} },
  26.             { Keys.F5, new List<string> {"Steam"} },
  27.             { Keys.F6, new List<string> {"Battle", "Blizzard", "Diablo", "Overwatch"} },
  28.             { Keys.F7, new List<string> {"Chrome"} },
  29.         };
  30.  
  31.         // Global hook instance
  32.         private static GlobalKeyboardHook gkh;
  33.  
  34.         // Tray icon
  35.         private static NotifyIcon notifyIcon;
  36.  
  37.         [STAThread]
  38.         static void Main()
  39.         {
  40.             // Initialize Windows Forms
  41.             ApplicationConfiguration.Initialize();
  42.  
  43.             // (Optional) Allocate a console to see debug logs/errors:
  44.             // AllocConsole();
  45.  
  46.             // Set up the notify icon with a context menu
  47.             var iconPath = Path.Combine(AppContext.BaseDirectory, "spat2.ico");
  48.             notifyIcon = new NotifyIcon
  49.             {
  50.                 Icon = new Icon(iconPath),
  51.                 Visible = true,
  52.                 ContextMenuStrip = new ContextMenuStrip
  53.                 {
  54.                     Items =
  55.                     {
  56.                         new ToolStripMenuItem("Exit", null, (s, e) => Application.Exit()),
  57.                         new ToolStripMenuItem("CTRL + F1 => Kill League/Riot"),
  58.                         new ToolStripMenuItem("CTRL + F2 => Kill Teams"),
  59.                         new ToolStripMenuItem("CTRL + F3 => Kill Discord"),
  60.                         new ToolStripMenuItem("CTRL + F4 => Kill Slack"),
  61.                         new ToolStripMenuItem("CTRL + F5 => Kill Steam"),
  62.                         new ToolStripMenuItem("CTRL + F6 => Kill Battle/Blizzard/etc."),
  63.                         new ToolStripMenuItem("CTRL + F7 => Kill Chrome")
  64.                     }
  65.                 }
  66.             };
  67.  
  68.             // Create a global keyboard hook
  69.             gkh = new GlobalKeyboardHook();
  70.  
  71.             // Hook the function keys we want to watch
  72.             gkh.HookedKeys.Add(Keys.F1);
  73.             gkh.HookedKeys.Add(Keys.F2);
  74.             gkh.HookedKeys.Add(Keys.F3);
  75.             gkh.HookedKeys.Add(Keys.F4);
  76.             gkh.HookedKeys.Add(Keys.F5);
  77.             gkh.HookedKeys.Add(Keys.F6);
  78.             gkh.HookedKeys.Add(Keys.F7);
  79.  
  80.             // Event handlers for KeyDown/KeyUp
  81.             gkh.KeyDown += Gkh_KeyDown;
  82.             gkh.KeyUp += Gkh_KeyUp;
  83.  
  84.             // Run the message loop
  85.             Application.Run();
  86.         }
  87.  
  88.         private static void Gkh_KeyDown(object sender, KeyEventArgs e)
  89.         {
  90.             // Check if CTRL is down
  91.             bool ctrlIsDown = (Control.ModifierKeys & Keys.Control) == Keys.Control;
  92.  
  93.             // If the pressed key is in our list AND CTRL is pressed
  94.             if (ctrlIsDown && KeyToProcessList.ContainsKey(e.KeyCode))
  95.             {
  96.                 // Mark handled so the key doesn't pass to the game
  97.                 e.Handled = true;
  98.  
  99.                 List<string> patterns = KeyToProcessList[e.KeyCode];
  100.                 Debug.WriteLine($"[KeyDown] CTRL+{e.KeyCode} => kill patterns: {string.Join(", ", patterns)}");
  101.  
  102.                 // Start a 10-second kill task
  103.                 Task.Run(() => KillProcessesRepeatedly(patterns));
  104.             }
  105.         }
  106.  
  107.         private static void Gkh_KeyUp(object sender, KeyEventArgs e)
  108.         {
  109.             // For this scenario, we may not need KeyUp logic,
  110.             // but you can handle it if you like
  111.         }
  112.  
  113.         private static void KillProcessesRepeatedly(List<string> processPatterns)
  114.         {
  115.             var start = DateTime.UtcNow;
  116.             while ((DateTime.UtcNow - start).TotalSeconds < 10)
  117.             {
  118.                 var processes = Process.GetProcesses();
  119.                 foreach (var p in processes)
  120.                 {
  121.                     // Don't kill ourself
  122.                     if (p.Id == Process.GetCurrentProcess().Id)
  123.                         continue;
  124.  
  125.                     // Compare each pattern
  126.                     foreach (var pattern in processPatterns)
  127.                     {
  128.                         if (p.ProcessName.IndexOf(pattern, StringComparison.OrdinalIgnoreCase) >= 0)
  129.                         {
  130.                             try
  131.                             {
  132.                                 p.Kill();
  133.                             }
  134.                             catch
  135.                             {
  136.                                 // ignore any exceptions
  137.                             }
  138.                             break; // done with this process
  139.                         }
  140.                     }
  141.                 }
  142.                 Thread.Sleep(100);
  143.             }
  144.         }
  145.     }
  146. }
  147.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement