title: Detect if key is held down by the user in C#
body: <p>How can I detect if the user is holding down the <code>Space</code> key in C#?</p>
  <p>In C++ you would add <code>&amp; 0x8000</code> as so:</p>
  <pre><code>while (true)
  {
      if (GetAsyncKeyState(VK_SPACE) &amp; 0x8000)
      {
          std::cout &lt;&lt; &quot;User is holding Space!&quot;;
      }
  }
  </code></pre>
  <p>I've tried to do the same in C# but didn't get far:</p>
  <pre><code>[DllImport(&quot;user32.dll&quot;)]
  public static extern short GetAsyncKeyState(Keys key);
  
  while (true)
  {
      if (GetAsyncKeyState(Keys.Space) &amp; 0x8000)
      {
          Console.WriteLine(&quot;User is holding Space!&quot;);
      }
  }
  </code></pre>
  <p>What am I doing wrong and how can I detect if the user is holding down spacebar?</p>