Skip to content
MPGHThe Dark Arts
/
RegisterLog in
Forum
Community
What's NewLatest posts across the boardTrendingHottest threads right nowSubscribedThreads you follow
Discussion
GeneralIntroductionsEntertainmentDebate FortFlaming & Rage
Board
News & AnnouncementsMPGH TimesSuggestions & HelpGiveaways
More Sections
Art & Graphic DesignProgrammingHackingCryptocurrency
Hacks & Cheats
Games
ValorantCS2 / CS:GOCall of Duty / WarzoneFortniteApex LegendsEscape From Tarkov
+14 moreLeague of LegendsGTA VMinecraftRustROTMGBattlefieldTroveBattleOnCombat ArmsCrossFireBlackshotRuneScapeDayZDead by Daylight
Resources
Game Hacking TutorialsReverse EngineeringGeneral Game HackingAnti-CheatConsole Game Hacking
Tools
Game Hacking ToolsTrainers & CheatsHack/Release NewsNew
Submit a release →Share your cheat, tool, or config with the community.
AINEW
AI Tools
General & DiscussionPrompt EngineeringLLM JailbreaksHotAI Agents & AutomationLocal / Open Models
AI × Gaming
AI Aimbots & VisionML Anti-CheatGame Bots & Automation
Create
AI Coding / Vibe CodingAI Art & MediaAI Voice & TTS
The AI frontier →Where game hacking meets modern machine learning. Jump in.
Marketplace
Buy & Sell
SellingBuyingTradingUser Services
Trust & Safety
Middleman LoungeMarketplace TalkVouch Copy Profiles
Money
Cryptocurrency TalkCurrency ExchangeWork & Job Offers
Start selling →List accounts, services, and goods. Use the middleman to trade safe.
MPGH The Dark Arts

A community for offensive security research, reverse engineering, and AI.

Community

ForumMarketplaceSearch

Account

RegisterLog in

Legal

Privacy PolicyForum RulesHelp & FAQ
© 2026 MPGH · All rights reserved.Built by the community, for the community. For educational purposes onlyContent is shared for security research and education — we don't condone illegal use. You're responsible for complying with applicable laws. Use at your own risk.
Home › Forum › Programming › C# Programming › Application.Exit

Application.Exit

Posts 1–4 of 4 · Page 1 of 1
LU
Lutherion
Application.Exit
Hello,
I use c# form. And what I have for now is a button down event and in that I have a if statement for the P key, and when I press this key. It closes the application, but it only closes when I have the form selected, how can you make it so, that when your in-game in maybe cs-go, you can close the c# form?
#1 · 8y ago
Hell_Demon
Hell_Demon
At the top of your class:
Code:
[DllImport("user32.dll")] 
public static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vlc);
[DllImport("user32.dll")]
public static extern bool UnregisterHotKey(IntPtr hWnd, int id);

const int EXIT_HOTKEY_ID = 1;
In your mainconstructor:
Code:
// The 6 is a modifier keycode: Alt = 1, Ctrl = 2, Shift = 4, Win = 8
// So 6 is ctrl+shift
RegisterHotKey(this.Handle, MYACTION_HOTKEY_ID, 6, (int) Keys.F4);
Somewhere in your main form
Code:
protected override void WndProc(ref Message m) 
{
    if (m.Msg == 0x0312 && m.WParam.ToInt32() == EXIT_HOTKEY_ID) 
    {
        // Your hotkey was pressed
    }
    base.WndProc(ref m);
}
Don't forget to unregister your hotkey on exit.
#2 · 8y ago
lemdpcfa
lemdpcfa
this is easy. don't need to unregister it.

Code:
using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Interop;

namespace class
{
    public class HotKey
    {
        private static Hashtable KeyPair = new Hashtable();
        private IntPtr Handle;
        private Window window;
        private uint Controlkey;
        private uint Key;
        private const int WM_HOTKEY = 786;

        public int KeyId { set; get; }

        public event HotKey.OnHotkeyEventHandeler OnHotKey;

        public void Regist(Window win, HotKey.KeyFlags control, Keys key)
        {
            Handle = new WindowInteropHelper(win).Handle;
            window = win;
            Controlkey = (uint)control;
            Key = (uint)key;
            KeyId = (int)Controlkey + (int)Key * 10;
            if (HotKey.KeyPair.ContainsKey((object)KeyId))
                throw new Exception("Error happened HOTKEY 0x12");
            if (!HotKey.RegisterHotKey(Handle, KeyId, Controlkey, Key))
                throw new Exception("Error happened HOTKEY 0x13");
            if (HotKey.KeyPair.Count == 0 && !HotKey.InstallHotKeyHook(this))
                throw new Exception("Error happened HOTKEY 0x12");
            HotKey.KeyPair.Add((object)KeyId, (object)this);
        }

        public void UnRegist(Window win, int KeyId)
        {
            HotKey.UnregisterHotKey(new WindowInteropHelper(win).Handle, KeyId);
        }

        [DllImport("user32")]
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint controlKey, uint virtualKey);

        [DllImport("user32")]
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);

        private static bool InstallHotKeyHook(HotKey hk)
        {
            if (hk.window == null || hk.Handle == IntPtr.Zero)
                return false;
            HwndSource hwndSource = HwndSource.FromHwnd(hk.Handle);
            if (hwndSource == null)
                return false;
            hwndSource.AddHook(new HwndSourceHook(HotKey.HotKeyHook));
            return true;
        }

        private static IntPtr HotKeyHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
        {
            if (msg == 786)
            {
                HotKey hotKey = (HotKey)HotKey.KeyPair[(object)(int)wParam];
                // ISSUE: reference to a compiler-generated field
                if (hotKey.OnHotKey != null)
                {
                    // ISSUE: reference to a compiler-generated field
                    hotKey.OnHotKey();
                }
            }
            return IntPtr.Zero;
        }

        ~HotKey()
        {
            HotKey.UnregisterHotKey(this.Handle, this.KeyId);
        }

        public delegate void OnHotkeyEventHandeler();

        public enum KeyFlags
        {
            Mod_None = 0,
            MOD_ALT = 1,
            MOD_CONTROL = 2,
            MOD_CONTROLALT = 3,
            MOD_SHIFT = 4,
            MOD_WIN = 8,
        }
    }
}

use it like that on form loaded():
Code:
            try {
                HotKey hotKey = new HotKey();
                hotKey.Regist((Window)this, HotKey.KeyFlags.Mod_None, Keys.F9);
                hotKey.OnHotKey += new HotKey.OnHotkeyEventHandeler(your_function);
            } catch { //error }
#3 · 7y ago
SH
shark17
Thanks for the useful information
#4 · 6y ago
Posts 1–4 of 4 · Page 1 of 1

Post a Reply

Similar Threads

  • Not a valid win32 applicationBy terence in General Game Hacking
    1Last post 20y ago
  • [Application] Undetected Module Maker V1.0By radnomguywfq3 in Visual Basic Programming
    72Last post 16y ago
  • Exit Fuckface Enter OutzidaBy OutZida in Art & Graphic Design
    8Last post 20y ago
  • how can i make Exit buttonBy sukh13 in WarRock - International Hacks
    9Last post 18y ago
  • WarRock Mod Applications[DISCUSSION]By BPK in General
    16Last post 18y ago

Tags for this Thread

None