Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: win32 equivalent of select()

Author: Scott Gasch

Date: 02:46:22 05/28/01

Go up one level in this thread


On May 28, 2001 at 01:46:16, Alex Boby wrote:

>
>Other than the dinky _kbhit(), is there a win32 equivalent of the all mighty
>select()? If not,.. how does everybody poll for input under windows?
>
>Sorry for the stupid question but I had a tough time finding anything with msdn.
>

I am a great fan of some things in Win32 but this is not one of them.  Below is
the code from my engine which was pulled from crafty after many an attempt to
figure it out reading MSDN.  The console mode Win32 interface leaves something
to be desired, IMHO.

    DWORD dw;
    static BOOL fInit = FALSE;
    static HANDLE hStdIn;
    static BOOL fPipe;

    if (g_fDeferredInput)
    {
        return(TRUE);
    }

    if (FALSE == fInit)
    {
        fInit = TRUE;
        hStdIn = GetStdHandle(STD_INPUT_HANDLE);
        fPipe = !GetConsoleMode(hStdIn, &dw);
        dw &= ~ENABLE_MOUSE_INPUT;
        dw &= ~ENABLE_WINDOW_INPUT;
        if (FALSE == fPipe)
        {
            SetConsoleMode(hStdIn, dw);
            FlushConsoleInputBuffer(hStdIn);
        }
    }

    if (TRUE == fPipe)
    {
        if (FALSE == PeekNamedPipe(hStdIn, NULL, 0, NULL, &dw, NULL))
        {
            return(1);
        }
        return(dw);
    }
    else
    {
        GetNumberOfConsoleInputEvents(hStdIn, &dw);
        return (dw <= 1) ? 0 : dw;
    }



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.