title: How to make a keyboard hook global across processes
body: <p>I am trying to create a utility keystroke app so i can do things like kill a preprogrammed process or launch something. I am thinking I should hold cmd in any app, then type in a 4 digit command key so I can launch or kill anything quickly while programming, debugging watching a video, etc.</p>
  
  <p>I figured out how to get the keyboard callback, but for whatever reason once I click into another app, my keystroke util receives no more keys. Even if I click back to my console window or msvc, I will not receive any input. This is unless its global, so how do I set the hook to be global?</p>
  
  <p>My code is</p>
  
  <pre><code>int main()
  {
      hook = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, GetModuleHandle(0), 0);
      MSG msg;
      while(GetMessage(&amp;msg, NULL, 0, 0) &gt; 0)
      {
          TranslateMessage(&amp;msg);
          DispatchMessage(&amp;msg);
      }
      UnhookWindowsHookEx(hook);
  }
  </code></pre>