title: How can I get my C# program to listen for a keypress held down, when it's not focused?
body: <p>I have a small program that I've written in a console application and I'm wondering if it's possible to have it listen to key events when the program is not focused.</p>
  
  <p>For example if I can run the application and while in a different application if I press and hold the alt key my c# program would register the key event and set a boolean to true when the key is held down.</p>
  
  <p>I did find this <a href="https://www.pinvoke.net/default.aspx/user32.registerhotkey" rel="nofollow noreferrer">https://www.pinvoke.net/default.aspx/user32.registerhotkey</a> but I can't figure out a way for it to detect if a key is held down.</p>