macgowan
March 10th, 2003, 03:48 PM
Hi --
I have a Win32 console application that takes user input using gets(). When the user presses the ESC key I would like to exit the current 'thing' the user is doing.
gets() seems to 'take over' until the user presses the RETURN key.
I am attempting to create two threads. The first thread is a UI thread that will do the get() functions and the second thread will monitor keypresses or messages for the ESC key.
I am having problems with thread priority. I have tryed some different priority settings and either get the user input and not the ESC key - or I get the ESC key and there is not user input.
Any comments ?
Thanks,
Chris
///////////////////////////////////////////////
// Starting the threads in the main()
// Create the monitor thread
Threadhandle = CreateThread(NULL, 0, ThreadprocESCMonitor, 0, 0, &Threadid);
// Set the priority
SetThreadPriority(Threadhandle, THREAD_PRIORITY_ABOVE_NORMAL);
// create the user interface thread
Threadhandle = CreateThread(NULL, 0, ThreadprocUserInterface, 0, 0, &Threadid);
// Set the priority
SetThreadPriority(Threadhandle, THREAD_PRIORITY_HIGHEST);
///////////////////////////////////////////////
// Thread ThreadprocUserInterface
DWORD WINAPI ThreadprocUserInterface(LPVOID lpParameter)
{
while (bLoop)
{
if (gfkbhit())
{
// The gets() are in the HandleCommands Function
HandleCommand(getkey());
}
}
return 0;
}
///////////////////////////////////////////////
// Thread ThreadprocESCMonitor
DWORD WINAPI ThreadprocESCMonitor(LPVOID lpParameter)
{
while (bLoop)
{
// Test for a key press
if (gfkbhit())
{
if (getkey() == ESC)
{
Beep(1000, 10);
}
}
}
return 0;
}
I have a Win32 console application that takes user input using gets(). When the user presses the ESC key I would like to exit the current 'thing' the user is doing.
gets() seems to 'take over' until the user presses the RETURN key.
I am attempting to create two threads. The first thread is a UI thread that will do the get() functions and the second thread will monitor keypresses or messages for the ESC key.
I am having problems with thread priority. I have tryed some different priority settings and either get the user input and not the ESC key - or I get the ESC key and there is not user input.
Any comments ?
Thanks,
Chris
///////////////////////////////////////////////
// Starting the threads in the main()
// Create the monitor thread
Threadhandle = CreateThread(NULL, 0, ThreadprocESCMonitor, 0, 0, &Threadid);
// Set the priority
SetThreadPriority(Threadhandle, THREAD_PRIORITY_ABOVE_NORMAL);
// create the user interface thread
Threadhandle = CreateThread(NULL, 0, ThreadprocUserInterface, 0, 0, &Threadid);
// Set the priority
SetThreadPriority(Threadhandle, THREAD_PRIORITY_HIGHEST);
///////////////////////////////////////////////
// Thread ThreadprocUserInterface
DWORD WINAPI ThreadprocUserInterface(LPVOID lpParameter)
{
while (bLoop)
{
if (gfkbhit())
{
// The gets() are in the HandleCommands Function
HandleCommand(getkey());
}
}
return 0;
}
///////////////////////////////////////////////
// Thread ThreadprocESCMonitor
DWORD WINAPI ThreadprocESCMonitor(LPVOID lpParameter)
{
while (bLoop)
{
// Test for a key press
if (gfkbhit())
{
if (getkey() == ESC)
{
Beep(1000, 10);
}
}
}
return 0;
}