title: Global hotkey in console application
body: <p>Does anyone know how to use the RegisterHotKey/UnregisterHotKey API calls in a console application?  I assume that setting up/removing the hotkey is the same, but how do I get the call back when the key was pressed?  </p>
  
  <p>Every example I see is for Winforms, and uses <code>protected override void WndProc(ref Message m){...}</code>, which isn't available to me.
  <hr>
  <b>update:</b> what I have is below, but the event is never hit. I thought it could be because when you load ConsoleShell it does block further execution, but even if I put <code>SetupHotkey</code> into a different thread nothing happens.  Any thoughts?</p>
  
  <pre><code>class Program
  {
      static void Main(string[] args)
      {
          new Hud().Init(args);
      }
  }
  
  class Hud
  {
      int keyHookId;
  
  
      public void Init(string[] args)
      {
          SetupHotkey();
          InitPowershell(args);
          Cleanup();
      }
  
      private void Cleanup()
      {
          HotKeyManager.UnregisterHotKey(keyHookId);
      }
  
      private void SetupHotkey()
      {
          keyHookId = HotKeyManager.RegisterHotKey(Keys.Oemtilde, KeyModifiers.Control);
          HotKeyManager.HotKeyPressed += new EventHandler&lt;HotKeyEventArgs&gt;(HotKeyManager_HotKeyPressed);
      }
  
      void HotKeyManager_HotKeyPressed(object sender, HotKeyEventArgs e)
      {
          //never executed
          System.IO.File.WriteAllText("c:\\keyPressed.txt", "Hotkey pressed");
      }
  
      private static void InitPowershell(string[] args)
      {
          var config = RunspaceConfiguration.Create();
          ConsoleShell.Start(config, "", "", args);
      }
  }
  </code></pre>