title: Global hotkeys in windowless .NET app
body: <p>I've read similar questions around this issue, including <a href="https://stackoverflow.com/questions/81150/best-way-to-tackle-global-hotkey-processing-in-c">Best way to tackle global hotkey processing in C#?</a> and <a href="https://stackoverflow.com/questions/2450373/set-global-hotkeys-using-c-sharp">Set global hotkeys using C#</a>. I've also investigated a NuGet package <a href="https://nuget.org/packages/GlobalHotKey/" rel="nofollow noreferrer">Global Hotkeys</a> which appears to be in its infancy. </p>
  
  <p>The problem here is, most of them seem to be designed for Winforms, or could probably run in WPF. The P/Invoke they're using seems to require a window handle. I'm thinking of having a windoless application here, i.e running without a main form or window, except when a certain key combo is pressed, so there might not actually be a handle. </p>
  
  <p>So, would passing a cheeky 0 as the Window handle for the P/Invoke cause it to not look for a window to process the keypress on? Or is my best bet here to use an invisible unfocusable Window? </p>
  
  <p>To add a little context, I'm making a windowless app to be used with TTS providing the feedback for control, my target audience here are blind and visually impaired users. Occasionally, things will have to be entered, so I want to be able to launch forms when necessary, but for the most part I'd like there to be no window cluttering things up. </p>
  
  <p>Some sample code (I can't verify if this would work properly yet).</p>
  
  <pre><code>[STAThread]
  static void Main()
  {
      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);
      ScreenReader.sapiEnable(true);
      ScreenReader.SayString("Launching application...");
      // bind hotkeys here
      Application.Run();
  }
  
  // called when the right keyboard shortcut is pressed
  static void ExitApp()
  {
      ScreenReader.SayString("Exiting program");
      Application.Exit();
  }
  </code></pre>
  
  <p>Thanks for any help you may be able to provide.</p>