|
-
March 11th, 2003, 11:01 AM
#4
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|