Read keyboard without event handler

Hi, I have a C# code that runs a time-consuming loop.
Is there a way to read the keyboard (ESC key) and escape from the loop? without the help of an event handler?

I found the following code

if(System.Input.Keyboard.IsKeyDown(Key.Esc))break;

but it seems like it is a function provided by WPF function, which seems a bit tricky to call from within a C# component.

Thanks.

There’s a Windows API: GetAsyncKey.

I’d recommend use GH_Document.IsEscapeKeyDown()

Thank you!!! This is exactly what I’ve been looking for!