<p>In VB6, I used a call to the Windows API, <strong>GetAsyncKeyState</strong>, to determine if the user has hit the ESC key to allow them to exit out of a long running loop.</p>

<pre><code>Declare Function GetAsyncKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
</code></pre>

<p>Is there an equivalent in pure .NET that does require a direct call to the API?</p>

You can find the P/Invoke declaration for GetAsyncKeyState from
http://pinvoke.net/default.aspx/user32/GetAsyncKeyState.html
Here's the C# signature for example:
```
```
[DllImport("user32.dll")]
static extern short GetAsyncKeyState(int vKey);
```
```