title: How to send keys data to a Console window without having focus
body: <p>I've been trying to send data to a console window without it having focus. I've used a simple Keyboard Hook from here: <a href="https://stackoverflow.com/questions/10988197/capture-keystroke-without-focus-in-console">Capture keystroke without focus in console</a></p>
  
  <p>I've modified the code provided from the answer on that page to display the unicode values of keys that have been pressed; my modifications are as follows:</p>
  
  <pre><code>private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr lParam)
  {
      if (nCode &gt;= 0 &amp;&amp; wParam == (IntPtr)WM_KEYDOWN)
      {
          var vkCode = Marshal.ReadInt32(lParam);
  
          var key = (Keys) vkCode;
  
          if (key == Keys.LShiftKey || key == Keys.RShiftKey)
              shift = true;
  
          if (key == Keys.RMenu)
              altgr = true;
  
          if (key == Keys.Return || key == Keys.Enter)
          {
              Console.WriteLine();
              input = "";
          }else if (key == Keys.Back)
          {
              if (input.Length &gt; 0)
              {
                  input = input.Substring(0, input.Length - 1);
                  Console.Write("\b \b");
              }
          }
          else
          {
              input += GetCharsFromKeys(key);
  
              Console.Write(GetCharsFromKeys(key));
          }
      }
  
      if (nCode &gt;= 0 &amp;&amp; wParam == (IntPtr) WM_KEYUP)
      {
          var vkCode = Marshal.ReadInt32(lParam);
  
          var key = (Keys)vkCode;
  
          if (key == Keys.LShiftKey || key == Keys.RShiftKey)
              shift = false;
  
          if (key == Keys.RMenu)
              altgr = false;
      }
      return CallNextHookEx(_hookID, nCode, wParam, lParam);
  }
  </code></pre>
  
  <p>The console does write what is being typed regardless of window focus, which is what is intended, however the issue is I have no idea how to allow the input and processing of data, like you would normally do using Console.ReadLine().</p>
  
  <p>I am using the following code to put the program in a message loop for the hook to work:</p>
  
  <pre><code>_hookID = SetHook(_proc);
  Application.Run();
  UnhookWindowsHookEx(_hookID);
  </code></pre>
  
  <p>In a nutshell, what I want to do is allow users to input data to the console regardless of window focus.</p>