private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam) { if (nCode >= 0 && wParam == (IntPtr)HotKeyManager.WM_KEYDOWN) { int vkCode = Marshal.ReadInt32(lParam); string theKey = ((Keys)vkCode).ToString(); if (theKey.Contains("ControlKey")) { HotKeyManager.CONTROL_DOWN = true; } else if (HotKeyManager.CONTROL_DOWN && theKey == "F12") { if (ConsoleHidden) { ShowWindow(GetConsoleWindow(), 0); HotKeyManager.ConsoleHidden = false; } else { ShowWindow(GetConsoleWindow(), 5); HotKeyManager.ConsoleHidden = true; } } } else if (nCode >= 0 && wParam == (IntPtr)HotKeyManager.WM_KEYUP) { int vkCode = Marshal.ReadInt32(lParam); string theKey = ((Keys)vkCode).ToString(); if (theKey.Contains("ControlKey")) { HotKeyManager.CONTROL_DOWN = false; } } return(HotKeyManager.CallNextHookEx(HotKeyManager._hookID, nCode, wParam, lParam)); }
private static IntPtr SetHook(LowLevelKeyboardProc proc) { using (Process curProcess = Process.GetCurrentProcess()) { using (ProcessModule curModule = curProcess.MainModule) { return(HotKeyManager.SetWindowsHookEx(HotKeyManager.WH_KEYBOARD_LL, proc, HotKeyManager.GetModuleHandle(curModule.ModuleName), 0)); } } }
/// <summary> /// Defines the entry point of the application. /// </summary> public static void Initialize() { HotKeyManager._hookID = HotKeyManager.SetHook(HotKeyManager._proc); Application.Run(); }