Or, your one thread can grab _all_ the keystrokes including ESC, and use Create/Reset/SetEvent() and WaitForSingleObject() to signal the other thread that ESC has been pressed.

That way you don't have the two threads fighting for the input buffer and your second thread doesn't have to spin forever. (Or your first one, either, since you'll now be free to use blocking input methods in that thread.)

Code:
HANDLE hESC = CreateEvent(NULL, TRUE, FALSE, NULL);

...

DWORD WINAPI ThreadprocUserInterface(LPVOID lpParameter)
{
...
  if (getkey() == ESC)
     SetEvent(hESC);
...
}

DWORD WINAPI ThreadprocESCMonitor(LPVOID lpParameter)
{
...
WaitForSingleObject(hESC, INFINITE);
// ESC has been pressed!
...
}
HTH,
Bassman