예제 #1
0
        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));
        }
예제 #2
0
 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));
         }
     }
 }
예제 #3
0
 /// <summary>
 /// Defines the entry point of the application.
 /// </summary>
 public static void Initialize()
 {
     HotKeyManager._hookID = HotKeyManager.SetHook(HotKeyManager._proc);
     Application.Run();
 }